我正在尝试在 Rails 3.1 上呈现一组评论,但网页上仅显示该集合的第一条评论(评论与想法相关联)。
首先,评论控制器:
def index
@comments = Comment.find_by_thought_id(params[:thought_id])
respond_to do |format|
format.html
format.js
end
end
然后,视图 index.js.erb
$("#thought_<%= params[:thought_id] %>").append("<%= escape_javascript(render'index') %>").effect("highlight", {}, 3000);
我正在渲染索引,所以现在到 _index.html.erb
<div id="comments_<%= params[:thought_id] %>">
<%= render @comments %>
</div>
最后是 _comment.html.erb
<%= div_for comment do %>
Posted <%=time_ago_in_words(comment.created_at)%> ago<br />
<%= link_to 'Delete', comment_path(comment), :method => :delete, :class => "delete", :remote => true %>
<%= content_tag(:p, comment.description, :class => "comment-body") %>
<% end %>
为什么 Rails 只给我一条评论?
提前致谢