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??
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??
You could define a view model class that contains the lists you need to fetch to the UI.
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?