While rendering a partial if we want to send parameters to the partial we can do it like this:
<%= render :partial => user_profile_list, :locals => { :user => @user } %>
or
<%= render :partial => "user_profile_list", :object => @user %>
or
<%= render "user_profile_list", :user => @user %>
_user_profile.html.erb
<div>
<p><%= user.name%></p>
<p><%= user.email %></p>
</div>
A smarter way to pass a collection as parameter to partial is:
<%= render :partial => user_profile_list, :collection => @users %>
_user_profile.html.erb
<div>
<p><%= user.name%></p>
<p><%= user.email %></p>
</div>
The above html code will be repeated for all the user in the collection @users .
0 Comment(s)