我正在尝试向此应用添加消息回复:https ://github.com/railstutorial/sample_app_2nd_ed
但是我不断收到错误消息:以下部分的未定义方法“内容”(第 17 行)。
<li>
<span class="content"><%= micropost.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
</span>
<% if current_user?(micropost.user) %>
<%= link_to "delete", micropost, method: :delete,
confirm: "You sure?",
title: micropost.content %>
<% end %>
<span>
<h>Comments</h>
<% @micropost.comments.each do |c| %>
<p>
<%=h c.content %>
</p>
<% end %>
</span>
<span>
<%= form_for(@comment) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_area :content, :cols => "20", :rows => "2", placeholder: "Compose new comment..." %>
</div>
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
</span>
</li>
这没有任何意义,因为例如第 2 行没有问题,而且我没有在我的 micropost 控制器或其他任何地方明确定义方法内容。我应该在哪里定义内容,我应该怎么做?
这是我的评论模型的代码
class Comment < ActiveRecord::Base
attr_accessible :content
belongs_to :micropost
validates :content, presence: true, length: { maximum: 140 }
validates :micropost_id, presence: true
default_scope order: 'comments.created_at DESC'
end