ngumamonene wrote: > just started using rails, the answer to this question might seem > obvious to others, but unfortunately not to me. > I am trying to create a grid of results using a collection and a > partial. > > but instead of using the <ul> tag or the table format, i am going to > use css. > That's whay i need to pass an incremental variable to each returned > result that could calculate its position within the grid. > Is there a way to retreive the row # within the partial the same way i > could get the index value in a for loop?
When you retrieve several model objects (e.g. @people = Person.find(:all)), that variable is just an ordinary array. So each Person object in the array has an associated index, starting at 0. If you render a partial using a collection like this: render(:partial => 'person', :collection => @people), Rails creates a local variable called 'person_counter' which contains the index number of the current object. (It's named after the name of the partial, not the collection, so if your partial is called 'bob' then you'll have to use 'bob_counter'.) Chris --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" 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-spinoffs -~----------~----~----~----~------~----~------~--~---
