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.

Naming a partial _when.html.erb throws a compile error

#4316

It appears to to happen for any reserved word like 'def' because it tries to set a variable of the partial name. Bug!

compile error
/rails/project/app/views/shared/filters/_when.html.erb:1: syntax error, unexpected kWHEN, expecting kEND ...lt];f = local_assigns[:f];when = local_assigns[:when];propos...

Rails 2.3.5

Reported by Zach Hale · April 3rd, 2010 @ 01:09 AM

State: wontfix
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Hugo Peixoto
    Hugo Peixoto

    When you create a partial such as _house.html.erb, it automatically passes the variable @house to a local variable named house. So, would you create a partial named _when.html.erb and you wouldn't be able to access the local variable named when. This, of course, isn't possible as 'when' is a reserved keyword.

    So to allow for the creation of "reserved keyword partials", this variable passing feature would have to be removed. I don't really see this as an option, so I'd rather add a note to the documentation stating this.

    September 18th, 2010 @ 08:10 PM

  2. Zach Hale
    Zach Hale

    A reasonable conclusion. It just really threw me for a loop. Maybe an error if a reserved word is used and called as a partial?

    September 18th, 2010 @ 08:25 PM

  3. Ryan Bigg
    Ryan Bigg
    • State changed from new to open
    • Importance changed from to Low

    I don't think this will be fixed. Catching the odd case where people name a partial that uses a reserved word will slow down partial rendering.

    September 18th, 2010 @ 11:05 PM

  4. David Trasbo
    David Trasbo
    • State changed from open to wontfix

    I'm with Ryan on this. Marking this wontfix for now. If anyone can propose a solution that doesn't slow down this performance critical part of Rails (and prove it with benchmarks, etc.) I'll be happy to re-open.

    September 25th, 2010 @ 06:10 PM