Skip to content

Commit

Permalink
rails g migration AddAuthorToBooks author:string
Browse files Browse the repository at this point in the history
  • Loading branch information
JunichiIto committed Sep 1, 2024
1 parent 6fe551e commit 411b916
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ def set_book

# Only allow a list of trusted parameters through.
def book_params
params.require(:book).permit(:title, :memo)
params.require(:book).permit(:title, :memo, :author)
end
end
5 changes: 5 additions & 0 deletions app/views/books/_book.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@
<%= book.memo %>
</p>

<p>
<strong>Author:</strong>
<%= book.author %>
</p>

</div>
5 changes: 5 additions & 0 deletions app/views/books/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
<%= form.text_area :memo %>
</div>

<div>
<%= form.label :author, style: "display: block" %>
<%= form.text_field :author %>
</div>

<div>
<%= form.submit %>
</div>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240901025850_add_author_to_books.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAuthorToBooks < ActiveRecord::Migration[7.2]
def change
add_column :books, :author, :string
end
end
3 changes: 2 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 411b916

Please sign in to comment.