I''m using render to display a collection of partials, where each partial is a table row. Is it possible to zebra-stripe the table using this method i.e. alternate table rows get a different CSS class? I can''t work out how each row partial would know whether it was odd or even. In the normal scheme of things I could do: <% odd_or_even = 0 for asset in @assets odd_or_even = 1 - odd_or_even -%> <tr class="line<%= odd_or_even %>"> <td... </tr> <% end %> However, it would be nice to replace the above with: <%= render :partial => ''asset'', :collection => @assets %> Thanks, John -- Posted via http://www.ruby-forum.com/.
John Topley wrote:> I''m using render to display a collection of partials, where each partial > is a table row. Is it possible to zebra-stripe the table using this > method i.e. alternate table rows get a different CSS class? I can''t work > out how each row partial would know whether it was odd or even. > > In the normal scheme of things I could do: > > <% odd_or_even = 0 > for asset in @assets > odd_or_even = 1 - odd_or_even -%> > <tr class="line<%= odd_or_even %>"> > <td... > </tr> > <% end %> > > However, it would be nice to replace the above with: > > <%= render :partial => ''asset'', :collection => @assets %> > > Thanks, > > John > >Refer to the example in the "Four Days with Rails" tutorial. It does exactly what you want using partials.. You need to use something like: <%= render_collection_of_partials "list_stripes", @items %> It''s explained on Page 27 of the tutorial :-) Hope this helps, Cheers Mohit.
That''s great, thank you! -- Posted via http://www.ruby-forum.com/.
On Sunday, June 25, 2006, at 5:57 PM, John Topley wrote:>That''s great, thank you! > > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsAlso take a look at ''cycle''. It''s used like this... <tr class="<%= cycle("even", "odd") %>"> ... use item ... </tr> _Kevin -- Posted with http://DevLists.com. Sign up and save your mailbox.