This project is archived and is in readonly mode.
PATCH: assign collection counter local variable in partials based on the :as option
Reported by Tekin | August 15th, 2008 @ 12:12 AM | in 2.x
A simple patch that adds a collection_size local variable to partial collections. Usefully specifically when you want to know if you are rendering the last item in the collection.
Also assigns a counter based on the :as option if it's set.
Comments and changes to this ticket
-
Tom Ward August 15th, 2008 @ 02:52 PM
Might it be nicer to automatically provide a helper method/instance variable to indicate whether the first or last records in the collection are being passed?
-
Tekin August 15th, 2008 @ 04:38 PM
- no changes were found...
-
Tekin August 15th, 2008 @ 04:38 PM
I guess so. In fact, Michael's patch does just that!
I've combined Michael's patch with mine, attached.
-
DHH August 16th, 2008 @ 05:29 AM
- State changed from new to wontfix
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 ;)
-
Tekin August 16th, 2008 @ 11:05 AM
- Title changed from PATCH: assign collection_size local variable in partials to PATCH: assign collection counter local variable in partials based on the :as option
A small part of the patch might still be worth keeping though - the part that creates a counter based on the :as parameter. It doesn't feel right that specifying the :as option doesn't set "#{:as}_counter". I've attached another patch.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 772 collection_size locals in collection partials see also: #836
- 772 collection_size locals in collection partials See reasoning for wontfix on #836