Particles and local variable

If we want to pass a collection to a partial one, we will do the following:

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

      

If we want to pass one object to a custom variable, we do the following:

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

      

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

+2


source to share


3 answers


Just pass it through locals like in your second example



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

      

+3


source


You can use another way to call partials:



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

      

+1


source


I found using: as a parameter is much more clear:

<%= render :partial => "item", :collection => @rabbits, :as => :item %>

      

+1


source







All Articles