Reputation: 15129
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)?
Upvotes: 2
Views: 575
Reputation: 15129
I found using :as parameter much more clear:
<%= render :partial => "item", :collection => @rabbits, :as => :item %>
Upvotes: 1
Reputation: 211540
You can make use of the other way of calling partials:
render(:partial => 'post', :object => @posts)
Upvotes: 1
Reputation: 6983
Just pass it through locals like in your second example
<%= render :partial => "item", :locals => { :posts => @posts } %>
Upvotes: 3