Tuesday, April 1, 2008

passing a variable to a partial

from here

Passing a variable to a partial means you can be clever about re-using your code to output different collections of data in the same way.



Essentially you just write:




<%= render :partial => '/path/to/_partial', :locals => { :items => @items } %>



The local variable items now makes each element of @items available in the partial. e.g.




<% for item in items -%>
do something...
<% end -%>

No comments: