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

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

php - How do you embed a video into a custom theme on WordPress? -