###実現したいこと
Railsで上記のような一覧と投稿が同一ページで見れるサイトを作りたいです。
###質問
form_for で投稿機能を作りたいのですが、表示されません。
ネットでエラーメッセージを検索したり、form_forの使い方を調べたり
したのですが、解決することができませんでした。
教えていただけると大変ありがたいです。
よろしくお願いします。
###該当のソースコード
【index.html.erb】
<table> <thead> <tr> <th>Title</th> <th>Body</th> <th></th> </tr> </thead> </table> <h2>New book</h2> <%= form_for(@book) do |f| %> <h4>Title</h4> <%= f.text_field :titel %> <h4>Body</h4> <%= f.text_area :body %> <%= f.submit 'Create Book' %> <% end %>
【books_controller.rb】
class
1 def show 2 end 3 4 def index 5 end 6 7 def new 8 @book = Book.new 9 end 10 11 def create 12 book = Book.new(book_params) 13 book.save 14 redirect_to books_path 15 end 16 17 def edit 18 end 19 20 private 21 def book_params 22 params.require(:book).permit(:title, :body) 23 end 24 25end 26

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/08 14:07
2020/05/08 21:05
2020/05/09 12:19