render collection with index

668 views
Skip to first unread message

Andrew Stone

unread,
Feb 17, 2007, 6:33:24 PM2/17/07
to rubyonra...@googlegroups.com
Is there any method for getting the current iteration (for changing row colors) in the category partial?

<%=render(:partial => "category", :collection => @categories)%>

thanks,
andy

--
Andrew Stone

Jean-François Trân

unread,
Feb 17, 2007, 6:40:53 PM2/17/07
to rubyonra...@googlegroups.com
Andrew :

> Is there any method for getting the current iteration (for changing row
> colors) in the category partial?
>
> <%=render(:partial => "category", :collection => @categories)%>

Use the variable category_counter in your partial.

-- Jean-François.

--
Ruby ( http://www.rubyfrance.org ) on Rails ( http://www.railsfrance.org )

Andrew Stone

unread,
Feb 17, 2007, 6:46:47 PM2/17/07
to rubyonra...@googlegroups.com
Use the variable category_counter in your partial.

   -- Jean-François.


Thanks so much!  I knew there had to be something there...just couldn't find it.

--
Andrew Stone

Aaron

unread,
Feb 17, 2007, 6:49:03 PM2/17/07
to Ruby on Rails: Talk
Andy,

The cycle method is a great way to do this. Here is an example:

<tr class="ListLine<%= cycle(0,1) %>">

Then just style ListLine0 and ListLine1.

Aaron

Andrew Stone

unread,
Feb 17, 2007, 6:55:43 PM2/17/07
to rubyonra...@googlegroups.com
That is cool.  I wish I new that before I wrote my row_class method. :)

--
Andrew Stone

Andrew Stone

unread,
Feb 17, 2007, 6:56:44 PM2/17/07
to rubyonra...@googlegroups.com

That is cool.  I wish I new that before I wrote my row_class method. :)


Also wish I could spell... ;)

sorry for the extra noise.

--
Andrew Stone
Reply all
Reply to author
Forward
0 new messages