ruby on rails - How can I remove this logic from my view? -


I am trying to wrap my head around this problem. I know that there should not be so much argument on them in the ideas. I have a user, post, and comments app. I users have many posts and comments.

  class user & lt; ActiveRecord :: Base has has_many: posts have_many: Comments  

Posts are user and there are many comments.

  class post & lt; ActiveRecord :: Base is has_many: Comments are_many: Comments are_to: Users  

Comments are from users and posts

  class comment & lt; ActiveRecord :: Base is_to: post is_to: user  

In my post #shows view, I show comments under the post. I want to show the name of the user who has commented. At the moment I have this in my opinion:

  <% @ post.comments.each do | Comment | & Gt%; & Lt; P & gt; & Lt; P & gt; Commenter: & lt; / P & gt; & Lt;% = link_to User.find (comment.userid) .login, User.find (comment.userid)%> & Lt; / P & gt; & Lt; P & gt; & Lt; P & gt; Comment: & lt; / P & gt; & Lt;% = comment.body% & gt; & Lt; / P & gt; & Lt;% end% & gt;  

I probably should have this argument in my post controller. But I am very confused @ Post.comments gives an array of comments related to the post (?), This means that I do not have the @commonter = @ postcomments. I'm confused with this problem so I can not explain it well. During the comment loop actually, you have user has_many

comment.user to get user data after declaring / code> comments . relations.


Comments