発生している問題・エラーメッセージ
Ruby(Ruby on Rails)で投稿編集画面を作成したのですが、投稿一覧画面及び詳細画面に編集結果が反映されません。 エラーメッセージは、表示されておりません。
該当のソースコード
bookscontrollerrb
1class BooksController < ApplicationController 2 def show 3 @book = Book.find(params[:id]) 4 end 5 6 def index 7 @books = Book.all 8 end 9 10 def new 11 @book = Book.new 12 end 13 14 def create 15 book = Book.new(book_params) 16 book.save 17 redirect_to book_path(book.id) 18 end 19 20 def edit 21 @book = Book.find(params[:id]) 22 23 end 24 25 def update 26 book = Book.find(params[:id]) 27 book.update(book_params) 28 redirect_to book_path(book.id) 29 30 end 31 32 def destroy 33 end 34 35 private 36 def book_params 37 params.permit(:title, :body) 38 end 39end
indexhtmlerb
1<h3>Books</h3> 2 3<table> 4<thead> 5<tr> 6<th>title</th> 7<th>body</th> 8<th></th> 9</tr> 10</thead> 11 12<tbody> 13<% @books.each do |book| %> 14<tr> 15<td> 16<%= book.title %> 17</td> 18<td> 19<%= book.body %> 20</td> 21<td> 22<%= link_to "show", book_path(book.id) %> 23<%= link_to "edit", edit_book_path(book.id) %> 24</td> 25</tr> 26<% end %> 27</tbody> 28</table> 29 30<h3>New book</h3> 31<%= form_with model:@book, local:true do |f| %> 32 <h5>Title</h5> 33 <%= f.text_field :title %> 34 <h5>Body</h5> 35 <%= f.text_area :body %> 36 <br><%= f.submit "Create Book" %></br> 37<% end %>
edithtmlerb
1<h3>Editing Book</h3> 2<%= form_with model:@book, local:true do |f| %> 3 <h5>Title</h5> 4 <%= f.text_field :title %> 5 <h5>Body</h5> 6 <%= f.text_area :body %> 7 <br><%= f.submit "Update Book"%></br> 8<% end %> 9<%= link_to "Show", book_path %> 10<%= link_to "Back", books_path %>
showhtmlerb
1<h5>Title:</h5> 2<%= @book.title %> 3<h5>Body:</h5> 4<%= @book.body %> 5<br></br> 6<%= link_to "Edit", edit_book_path(@book) %> 7<%= link_to "Back", books_path %>
試したこと
色々調べ試してみましたが、解らず、また独学のため周りに聞ける方がおらず、質問させていただきました。
補足情報(FW/ツールのバージョンなど)
rails バージョン 5.2.5, rubyバージョン2.6.8
作成したモデルは、Book テーブルはbooksになります。カラムは、title, bodyになります。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/12/16 09:26
2021/12/16 09:42
2021/12/16 10:21