Reputation: 85
This is my posts#index so far:
<% @posts.each do |post| %>
<%= post.title %><br>
<%= post.body %> <br>
<b>Author:</b> <%= post.user_id %>
<% end %>
I'd like to put user.email there instead of id. How can i do that? Thanks.
Upvotes: 0
Views: 50
Reputation: 613
Please have a look at Rails docs for model associations.
Long story short, you should have a relationship between post and user (a users have many posts) and get the email like post.user.email
Upvotes: 1