Rails: rendering collection of different models -
i have defined @results
variable in controller contains different models , want render them in view using <%= render @results
%>.
how can give render
method address directory contains partials these models.
solution
<% @results.each |result| %> <%= render "home/partials/#{result.class.name.downcase}", result.class.name.downcase.to_sym => result%> <% end %>
render in current object's view directory:
render 'form' # renders _form.html.erb in same directory
to in directory, add it's directory name:
render 'shared/form' # renders _form.html.erb in views/shared/
since results variable apparently contains multiple models, assign directory
value each entry in hash or array , call in view or controller.
that's best can give based on very, little information in question.
Comments
Post a Comment