Skip to content

Commit

Permalink
Add slug to Book model
Browse files Browse the repository at this point in the history
  • Loading branch information
dsomel21 committed Feb 14, 2024
1 parent 7f68a83 commit a07fe82
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/views/books/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
json.key_format! :camelize => :lower

json.books do
json.array!(@books, :id, :sequence, :title, :en_title, :en_short_summary, :en_synopsis, :artwork_url, :number_of_chapters_released)
json.array!(@books, :id, :sequence, :title, :en_title, :en_short_summary, :en_synopsis, :artwork_url, :number_of_chapters_released, :slug)
end
39 changes: 39 additions & 0 deletions db/migrate/20240214064320_add_slug_to_books.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class AddSlugToBooks < ActiveRecord::Migration[7.0]
def change
add_column :books, :slug, :string
add_index :books, :slug, :unique => true

reversible do |dir|
dir.up do
slug_mappings = [
{ :id => 1, :slug => 'nanak-prakash-purbardh' },
{ :id => 2, :slug => 'nanak-prakash-utrardh' },
{ :id => 3, :slug => 'raas-1' },
{ :id => 4, :slug => 'raas-2' },
{ :id => 5, :slug => 'raas-3' },
{ :id => 6, :slug => 'raas-4' },
{ :id => 7, :slug => 'raas-5' },
{ :id => 8, :slug => 'raas-6' },
{ :id => 9, :slug => 'raas-7' },
{ :id => 10, :slug => 'raas-8' },
{ :id => 11, :slug => 'raas-9' },
{ :id => 12, :slug => 'raas-10' },
{ :id => 13, :slug => 'raas-11' },
{ :id => 14, :slug => 'raas-12' },
{ :id => 15, :slug => 'rut-1' },
{ :id => 16, :slug => 'rut-2' },
{ :id => 17, :slug => 'rut-3' },
{ :id => 18, :slug => 'rut-4' },
{ :id => 19, :slug => 'rut-5' },
{ :id => 20, :slug => 'rut-6' },
{ :id => 21, :slug => 'ayaan-1' },
{ :id => 22, :slug => 'ayaan-2' }
]

slug_mappings.each do |mapping|
Book.find_by(:id => mapping[:id])&.update(:slug => mapping[:slug])
end
end
end
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a07fe82

Please sign in to comment.