0
我正在ROR項目,並創建了部分表單的評論,但我得到show.html.rb「未定義的方法`評論'」錯誤。我試圖找到什麼是長期的,但錯誤的沒有luck.The亮點是這一形象未定義的方法`評論'
這裏是我的_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