I am using gem devise for creating users profile
Each user can create a comment. I need to add the user name beside each comment something like this <%= @comment.us
You could do it the other way around, in your show
method:
@comments = Comment.all
in your show
view:
<% @comments.each do |comment| %>
<%= comment.text %>
<%= comment.user.name %>
<% end %>
Since your question is not really clear I'll specifiy that if you want to show just the comments posted by the user:
def show
user_id = User.find(params[:id]).id
@comments = Comment.where(user_id: user_id)
end