0
私はRORプロジェクトに取り組んでいて、コメント用の部分フォームを作成しましたが、show.html.rb" undefined method `comments'"でエラーが発生しました。エラーのないluck.Theのハイライトは、この画像ここ未定義のメソッド `comments '
にされていないことは、私の_form.html.erb
<%= simple_form_for ([@message, @message.comments.build]) do |f| %>
<%= f.input :content , label: "Comments" %>
<%= f.button :submit, :class => "btn-custom" %>
<% end %>
class CommentsController < ApplicationController
def create
@message = Message.find(params[:message_id])
@comment = @message.comments.create(comment_params)
@comment.user_id = current_user.user_id
if @comment.save
redirect_to message_path(@message)
else
render 'new'
end
end
private
def comment_params
params.require(:comment).permit(:content)
end
end
であり、これは私のshow.html.rbある
<div class="col-md-10 col-md-offset-1">
<div class="message-show">
<h2><%[email protected] %></h2>
<p class="message-posted-by"><%= time_ago_in_words(@message.created_at) %>
ago </p>
<p class="message-desc"><%= @message.description %></p>
<h3 class="comment-section-header">Discussion:</h3>
<p><%= render @message.comments %></p>
<h3 class="reply-to-msg">Reply</h3>
<%= render 'comments/form' %>
<div class="links btn-group">
<%= link_to "Back", root_path, class: "btn btn-default" %>
<%= link_to "Edit", edit_message_path, class: "btn btn-primary" %>
<%= link_to "Delete",message_path(@message), method: :delete,data: {confirm:"Are you sure?"} , class: "btn btn-danger" %>
</div>
</div>
</div>
、あなたのモデルを投稿することができますか? – Pavan
完全なエラーメッセージを追加できますか? '未定義のメソッドコメント........ 'のようなものを言うべきである場合 – aBadAssCowboy