On Wed, Sep 30, 2009 at 2:05 PM, Shaun Pearl
<[email protected]> wrote:
>
> I guess my real question is,
>
> Why does the cycle reset on subsequent renderings of the partial? Doing
> it with JS is fine, I'm more curious as to why this doesn't work though.
> Apologies if my intent wasn't too clear in the original post!
>
> I shall just do it using JS for now anyway, but would love to know whats
> going on behind the scenes in the example I gave :)


If you want it to know what style/class to draw next you need a better
cycle() method, one that tracks it's own state across multiple
requests.  I have this alt method in one of my Rails apps:

def alt( s='', s2=' class="alt-row"' )
  session[:alt] ||= '1'
  session[:alt] = session[:alt] == '1' ? '2' : '1'
  session[:alt] == '1' ? s2 : s
end

Usage is just: <tr<%= alt %>


But using jQuery is just as easy:

$("tr:nth-child(odd)").addClass("odd");



-- 
Greg Donald
http://destiney.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to