我有3个模型user has many articles
,user has many comments
,articles belongs to user
,comments 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 %>
答案 0 :(得分:1)
您应该添加一个Comment
也属于User
。
然后:<%= comment.user.name %>
(如果用户模型具有name属性)