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.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

Partial collection counter variable improperly named using :as

#2804

This is my first bug submission, so please forgive any deviations from protocol.

It seems that the :as option doesn't affect the counter variable name when rendering a collection. Here is an example.

From a brand new 2.3.2 app...


# [ApplicationController#index]

<% @cheesecakes = %w(strawberry chocolate graham-cracker) %>
<%= render :partial => "item", :collection => @cheesecakes, :as => :cheesecake %>

# [application/_item.html.erb]

<%= "#{item_counter+1} #{cheesecake}" %>
</br>
[OUTPUT]

1 strawberry 
2 chocolate 
3 graham-cracker

Should this "item_counter" not be "cheesecake_counter"? Instead "cheesecake_counter" does not exist.

undefined local variable or method `cheesecake_counter'

Reported by graham (at votary) · June 16th, 2009 @ 01:13 AM

State: resolved
Milestone: 2.3.6
Assigned to: nobody
Importance: none

Activity

  1. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  2. Dan Pickett
    Dan Pickett
    • Tag changed from 2-3-stable, partial, partial_counter, render to 2-3-stable, bugmash, partial, partial_counter, render

    May 9th, 2010 @ 07:12 PM

  3. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag changed from 2-3-stable, bugmash, partial, partial_counter, render to 2-3-stable, bugmash, master, partial, partial_counter, render, verified

    Verified on master and 2-3-stable using the code snippet Graham provided.

    May 15th, 2010 @ 10:49 AM

  4. Jeff Kreeftmeijer
    Jeff Kreeftmeijer

    I've attached a patch that allows you to use cheesecake_counter in addition to item_counter in the above example for master. I'm working on a patch for 2-3-stable as we speak.

    May 15th, 2010 @ 12:36 PM

  5. Jeff Kreeftmeijer
    Jeff Kreeftmeijer

    And here's the patch for 2-3-stable. :)

    May 15th, 2010 @ 01:12 PM

  6. Jeff Kreeftmeijer
    Jeff Kreeftmeijer

    Sorry, was using wrong ticket numbers in my commit messages so I removed the patches. Here they are again.

    May 15th, 2010 @ 01:19 PM

  7. Jeff Kreeftmeijer
  8. Anil Wadghule
    Anil Wadghule

    +1 for this patch. I verified it against Rails master. It definitely helps in improving readability of code.

    May 15th, 2010 @ 01:41 PM

  9. Rizwan Reza
    Rizwan Reza
    • Tag changed from 2-3-stable, bugmash, master, partial, partial_counter, render, verified to 2-3-stable, bugmash, bugmash-review, master, partial, partial_counter, render, verified
    • State changed from new to verified

    May 15th, 2010 @ 05:03 PM

  10. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 3.x to 2.3.6

    May 15th, 2010 @ 06:32 PM

  11. Repository
  12. Repository
  13. Rizwan Reza
    Rizwan Reza
    • Tag changed from 2-3-stable, bugmash, bugmash-review, master, partial, partial_counter, render, verified to 2-3-stable, master, partial, partial_counter, render, verified

    May 15th, 2010 @ 06:35 PM

  14. Jeremy Kemper
    Jeremy Kemper
    • State changed from resolved to incomplete

    Fix failing tests.

    May 15th, 2010 @ 06:44 PM

  15. Jeff Kreeftmeijer
    Jeff Kreeftmeijer

    Needed to check if as is set before trying to create a counter for it. I’ve attached a patch. :)

    May 15th, 2010 @ 07:11 PM

  16. Repository
    Repository
    • State changed from incomplete to resolved

    May 15th, 2010 @ 07:22 PM

  17. Repository