While passing objects to partial we can change the name of the local variable in the partial and for that purpose we need to use the :as option.
For example we have a partial _account.html.erb where we need to pass a collection @cutomers as local variable user . We will do it like this:
<%= render partial: "account", collection: @cutomers, as: 'user' %>
_account.html.erb
<div>
<p><%= user.name%></p>
<p><%= user.email%></p>
</div>
0 Comment(s)