Question

If we want to pass a collection to partial, we do like this:

<%= render :partial => "post", :collection => @posts %>

If we want to pass a single object within a custom variable, we do this:

<%= render :partial => "item", :locals => { :item => @advertisement } %>

Now what should I do to to pass a collection, "proxying" it through a custom variable (like the second case)?

Was it helpful?

Solution

Just pass it through locals like in your second example

<%= render :partial => "item", :locals => { :posts => @posts } %>

OTHER TIPS

You can make use of the other way of calling partials:

render(:partial => 'post', :object => @posts)

I found using :as parameter much more clear:

<%= render :partial => "item", :collection => @rabbits, :as => :item %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top