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.

Templates that use with_options...

#4429

If I do something like:

= form_for some_object do |form|
  - form.with_options :class => 'text' do |input|
    = input.text_field :description

Under production mode in Rails 3.0 (trunk/beta3, with Ruby 1.9.2 x64 trunk) will output the text_field twice. This doesn't happen in development mode.

Admittedly this is in HAML, but pretty certain this will happen in ERB too, as I guess this is to do with fixing helpers like form_for and form_tag that output text within a do block as they previously needed to use '-' instead of '=' while using concat behind the scenes.

The use of the '-' notation in templates shouldn't output anything is my take (exception being form_for, form_tag etc purely for some level of backward compatibility with Ruby 2.x)

Oddly enough, this happens with the with_options method, but I don't seem to notice it with loops such as for statements or Array#each calls

Reported by VirtualFunction · April 17th, 2010 @ 04:04 PM

State: resolved
Milestone: 3.0.2
Assigned to: Yehuda Katz (wycats) Yehuda Katz (wycats)
Importance: High

Activity

  1. David Workman
    David Workman

    There is an error there... you are using '=' for the form_for line.

    April 17th, 2010 @ 04:37 PM

  2. iain
    iain

    @David: That's not an error. In Rails 3 you should do this. That works even in HAML.

    April 17th, 2010 @ 10:13 PM

  3. José Valim
    José Valim
    • Milestone cleared.
    • State changed from new to open
    • Assigned user set to Yehuda Katz (wycats)
    • Importance changed from to High

    August 27th, 2010 @ 07:45 PM

  4. Carlos Antonio da Silva
    Carlos Antonio da Silva

    This error just happened to me while in development, and I created a test case showing the issue.
    The same patch attached is also in this pastie: http://pastie.org/private/t66q1nzqhrwg0afl1bkmw, which contains the test suite output showing the double render issue.

    August 27th, 2010 @ 07:51 PM

  5. Marjan Krekoten'
    Marjan Krekoten'

    I attached patch that fixes this issue. It also contains test patch from Carlos Antonio da Silva.

    August 28th, 2010 @ 08:24 PM

  6. VirtualFunction
    VirtualFunction

    Many thanks everyone with the recent activity here. Just curious, will these patches make HAML work as expected too? If not I assume I will need to also raise this with the HAML dev(s)

    August 28th, 2010 @ 10:05 PM

  7. Jeremy Kemper
  8. Trotter Cashion
    Trotter Cashion

    The patch from Marjan works for us on the 3-0-stable branch. Had an conflict applying it to master, however. Let us know if you'd like us to patch.

    September 14th, 2010 @ 12:40 AM

  9. Marjan Krekoten'
  10. José Valim
    José Valim
    • State changed from open to resolved

    This is already fixed in master.

    September 23rd, 2010 @ 10:48 PM

  11. Marjan Krekoten'
    Marjan Krekoten'

    Cool. Can you please point me to commit that fixed this issue? I can't find it but it is interesting for me for self education.

    Thx!

    September 23rd, 2010 @ 11:25 PM

  12. Jeremy Kemper
  13. Justin Halsall
    Justin Halsall

    I'm looking at master and it seems as if the patch hasn't been added.

    January 20th, 2011 @ 02:54 PM

  14. Samuel Kadolph
    Samuel Kadolph

    This patch isn't applied in master or 3-0-stable.

    For anyone that needs it now, put this in config/initializers.

    January 20th, 2011 @ 02:56 PM

  15. José Valim
    José Valim

    The patch wasn't applied on master but it was fixed in a different way. I have even pushed the test case added by Carlos.

    We won't apply the patch to 3-0-stable because whitelistening "with_options" is too brittle as solution to be applied in Rails as whole.

    January 20th, 2011 @ 03:00 PM

  16. mdrozdziel
    mdrozdziel

    I am still getting this error with 3.0.5. What is the best workaround?

    February 28th, 2011 @ 03:30 PM