Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

PATCH: assign collection counter local variable in partials based on the :as option

#836

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.

Reported by Tekin · August 15th, 2008 @ 12:12 AM

State: wontfix
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Michael Bumann
  2. Tekin
  3. Tom Ward
    Tom Ward

    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?

    August 15th, 2008 @ 02:52 PM

  4. Tekin
  5. Tekin
    Tekin

    I guess so. In fact, Michael's patch does just that!

    I've combined Michael's patch with mine, attached.

    August 15th, 2008 @ 04:38 PM

  6. DHH
    DHH
    • 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 ;)

    August 16th, 2008 @ 05:29 AM

  7. Tekin
    Tekin
    • 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.

    August 16th, 2008 @ 11:05 AM