博客及其作者和评论者[如何使它们出现]

时间:2013-05-11 14:57:06

标签: ruby-on-rails ruby-on-rails-3.2

我有3个模型user has many articlesuser has many commentsarticles belongs to usercomments belongs to user,如何让用户的名字出现在评论或文章中张贴?

<%= div_for comment do %>
  <p><strong><%=  %> says</strong></p> # how should i write a condition here to make the name of the commenter appear when he puts a comment
  <%= simple_format comment.content %>
<% end %>

1 个答案:

答案 0 :(得分:1)

您应该添加一个Comment也属于User

然后:<%= comment.user.name %>(如果用户模型具有name属性)