前提・実現したいこと
掲示板アプリの作成中でコメント機能をつけるためにRailsガイドを参考にコードを書いたのですがどうにもうまくいかず以下のようなエラーが出ます。
発生している問題・エラーメッセージ
SyntaxError in PostsController#show /Users/oohirakatsuya/prac/bbs/app/views/posts/show.html.erb:43: syntax error, unexpected tLABEL ...ffer.append= form_with (model: @post, @post.comments.build, ... ^~~~~~ /Users/oohirakatsuya/prac/bbs/app/views/posts/show.html.erb:44: syntax error, unexpected tLABEL, expecting '=' local: true) do |f| @output_buffer.... ^~~~~~ /Users/oohirakatsuya/prac/bbs/app/views/posts/show.html.erb:70: syntax error, unexpected keyword_ensure, expecting end-of-input ensure ^~~~~~ Extracted source (around line #43): 41 42 43 44 45 46 <h2>コメントをする</h2> <%= form_with (model: @post, @post.comments.build, local: true) do |f| %> <p> Rails.root: /Users/oohirakatsuya/prac/bbs Application Trace | Framework Trace | Full Trace app/views/posts/show.html.erb:43: syntax error, unexpected tLABEL app/views/posts/show.html.erb:44: syntax error, unexpected tLABEL, expecting '=' app/views/posts/show.html.erb:70: syntax error, unexpected keyword_ensure, expecting end-of-input Request Parameters: {"id"=>"8"} Toggle session dump Toggle env dump Response Headers: None x >>
該当のソースコード
comments_controller.rb
class CommentsController < ApplicationController def create @post = Post.find(params[:post_id]) @comment = @post.comments.create(comment_params) redirect_to post_path(@post) end private def comment_params params.require(:comment).permit(:commenter, :body) end end
show.html.erb
<h2>コメントをする</h2> <%= form_with (model: @post, @post.comments.build, local: true) do |f| %> <p> <%= f.label :お客さん %><br> <%= f.text_field :commenter %> </p> <p> <%= f.label :コメント %><br> <%= f.text_area :comment %> </p> <p> <%= f.submit %> </p> <% end %>
なぜこのようなエラーが出るか分かる方いましたら助けてください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。