0

could the following code be refactored and simplified by using the collection parameter of partials? I can't see how it could be done because of the "path" local variable being passed in.

<% @admins.each do |admin| %>
  <%= render :partial => 'person', :locals => { :person => admin, :path => edit_admin_path(admin) } %>
<% end if @admins %>

<% @users.each do |user| %>
  <%= render :partial => 'person', :locals => { :person => user, :path => edit_user_path(user) } %>
<% end if @users %>
pingu
  • 8,719
  • 12
  • 50
  • 84

1 Answers1

4

Make use of rendering collections:

<%= render :partial => "person", :collection => @users + @admins %>

# in person.html.erb
path = person.admin? edit_admin_path(person) : edit_user_path(person)
clyfe
  • 23,695
  • 8
  • 85
  • 109