I write this code:
<% @user.posts.each do |post| %>
<%= render 'post', locals: { post: post, user: @user} %>
<% end %>
Then in _post.htm.erb
I write follow code:
<div class="post-title">
<img src="<%= @user.avatar.url%>" class="img-rounded post-image">
<h4 id="post-name"><%= @user.first_name + ' ' [email protected]_name %> </h4>
<div id="post-date"><%= post.created_at.strftime('%d %b - %k:%M') %></div>
</div>
<div class="post-content">
<p><%= post.content %></p>
</div>
<%= render 'like', post:post %>
<li class="post-divider"></li>
When I go to this page, I see follow:
undefined local variable or method `post'
You need to use partial: when you pass locals to a partial as follows:
I hope this will help you.