Have the following code throwing an error. I’ve always just jury-rigged something before but want to learn the proper way. Is the proper way to pass the local variables? Say you also have an instance variable you want to use in the partial?
@users is an array of user emails
<% @users.each do |email| %>
<%= render :partial => 'user/foobar' %>
<% end %>
user/foobar
<div id="user_<%= email %>>
<div><%= email %></div>
</div>
EDIT: also will want to use the partial in a js file after adding an email address. Would I set the instance after create to @user or something else?
You don’t need to use
each. You can use the:collectionoption:In
user/_foobar.html.erbpartial (below, the automatically-created local variablefoobarwill contain the current instance of an item from the@userscollection):The local variable is named after the name of the partial. See guide here.