views:

58

answers:

2

I have 3 models: parent-companies, companies and contacts that I'd like to list then all on one index page with 3 different partials depending on the model.

Is there a clean way to do this??

A: 

You could define a view model class that contains the lists you need to fetch to the UI.

eglasius
+1  A: 

Perhaps something like this?

<% @objects.each do |obj| %>
  <% klass = obj.class_name.to_s.tableize.singularize %>
  <%= render :partial => "#{klass}", :locals => {"#{klass}".to_sym => obj} %>
<% end %>

Still four lines of code, and you lose clarity. Why not just list the three calls to partials?

Matt Darby