前提
コメント投稿時送信を押したあとエラーが出ます
実現したいこと
コメントの保存する
発生している問題・エラーメッセージ
NoMethodError in CommentsController#create undefined method `comment' for #<Comment:0x00007fb892def830> Did you mean? committed! Extracted source (around line #5): 3 4 5 6 7 8 def create @comment = Comment.new(comment_params) if @comment.save redirect_to prototype_path(@comment.prototype_id) else @prototype = @comment.prototype_id Rails.root: /Users/mishirotakenori/projects/protospace-38413-1のコピー Application Trace | Framework Trace | Full Trace app/controllers/comments_controller.rb:5:in `create' Request Parameters: {"authenticity_token"=>"OI+vWAALiK1+ADc72ZNR6H4y0GSiS8Ulpt80io7zqQimYHiHsW12w9JqBUHpAXrqaXEJCvGlY4pL/RZCFWrgAg==", "comment"=>{"text"=>"swsws"}, "commit"=>"送信する", "prototype_id"=>"5"}
該当のソースコード
comments.controller.rb
1class CommentsController < ApplicationController 2 3 def create 4 @comment = Comment.new(comment_params) 5 if @comment.save 6 redirect_to prototype_path(@comment.prototype_id) 7 else 8 @prototype = @comment.prototype_id 9 @comments = @prototype.comments 10 render "prototypes/show" 11 end 12 end 13 14 private 15 def comment_params 16 params.require(:comment).permit(:text).merge(user_id: current_user.id, prototype_id: params[:prototype_id]) 17 end 18 19end
show.html.erb
1<main class="main"> 2 <div class="inner"> 3 <div class="prototype__wrapper"> 4 <p class="prototype__hedding"> 5 <%= @prototype.title %> 6 </p> 7 <%= link_to @prototype.user.name, user_path(@prototype.user_id), class: :prototype__user %> 8 <% if user_signed_in? && current_user.id == @prototype.user_id %> 9 <div class="prototype__manage"> 10 <%= link_to "編集する", edit_prototype_path(@prototype.id), class: :prototype__btn %> 11 <%= link_to "削除する", prototype_path(@prototype.id), method: :delete, class: :prototype__btn %> 12 </div> 13 <% end %> 14 <div class="prototype__image"> 15 <%= image_tag @prototype.image %> 16 </div> 17 <div class="prototype__body"> 18 <div class="prototype__detail"> 19 <p class="detail__title">キャッチコピー</p> 20 <p class="detail__message"> 21 <%= @prototype.catch_copy %> 22 </p> 23 </div> 24 <div class="prototype__detail"> 25 <p class="detail__title">コンセプト</p> 26 <p class="detail__message"> 27 <%= @prototype.concept %> 28 </p> 29 </div> 30 </div> 31 <div class="prototype__comments"> 32 <% if user_signed_in? %> 33 <%= form_with model: [@prototype, @comment], local: true do |f|%> 34 <div class="field"> 35 <%= f.label :text, "コメント" %><br /> 36 <%= f.text_field :text %> 37 </div> 38 <div class="actions"> 39 <%= f.submit "送信する", class: :form__btn %> 40 </div> 41 <% end %> 42 <% end %> 43 <ul class="comments_lists"> 44 <% @comments.each do |comment| %> 45 <li class="comments_list"> 46 <%= comment.text %> 47 <%= link_to comment.user.name, user_path(comment.user_id), class: :comment_user %> 48 </li> 49 <% end %> 50 </ul> 51 </div> 52 </div> 53 </div> 54</main>
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
params の中身はどうなってますか?

あなたの回答
tips
プレビュー