I often find myself find my self doing something like this: <%= render :partial => ''products'', :collection => @products, :locals => {:collection_size => @products.size} %> Usually when I need to identify the last item so I can give it a specific class. I figured it would be much more useful if the collection size was automatically assigned as a local variable in the same way the counter is. Here''s a patch that does just that. http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/836-assign-collection_size-local-variable-in-partials It also assigns a counter based on the :as option if it''s set. Tekin Suleyman --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Tekin Suleyman
2008-Aug-15 12:37 UTC
Re: Patch that adds a collection_size local to partials
It appears another patch that does almost exactly the same thing is also in lighthouse (#772), anyone have any comments?> Here''s a patch that does just that. > > http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/836-assign-collection_size-local-variable-in-partials >Tekin Suleyman --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
> I figured it would be much more useful if the collection size was > automatically assigned as a local variable in the same way the counter > is. > > Here''s a patch that does just that. > > http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/83...Copied from wontfix reasoning: I''m really not a fan of this auto-setting of locals. I think setting the counter local is already kinda fishy, but at least it''s something that would otherwise be kinda hard. Setting the size of the collection is perfectly doable through current means, so I don''t think it''s worth the magic spell to do it automatically. You''re of course always free to turn it into a plugin ;) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Tekin Suleyman
2008-Aug-16 09:20 UTC
Re: Patch that adds a collection_size local to partials
> > You''re of course always free to turn it into a plugin ;) >Fair enough. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---