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.

undefined method `protect_against_forgery?' for #<ActionView::Base:0x10ad1a500>

#4700

In a test for the new.html.erb template generated in the scaffold generator, rendering the template results in undefined method 'protect_against_forgery?'.

This is happening because new.html.erb renders _form.html.erb, which calls form_for, which calls FormTagHelper#extra_tags_for_form, which calls protect_from_forgery?, which is not defined in the scope in which it is being called.

I've got a patch that fixes this:
http://github.com/dchelimsky/rails/commit/53ba21a30fd359744cdee9acd...

Admittedly this is not perfect, but it does solve this problem without bleeding into other areas of the system.

Reported by David Chelimsky · May 26th, 2010 @ 07:08 AM

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

Activity

  1. David Chelimsky
    David Chelimsky
    • Tag set to action_view, patch, testing
    • Assigned user set to José Valim

    May 26th, 2010 @ 07:09 AM

  2. David Chelimsky
    David Chelimsky
    • Assigned user changed from José Valim to Carl Lerche

    May 26th, 2010 @ 07:10 AM

  3. David Chelimsky
    David Chelimsky
    • Assigned user changed from Carl Lerche to Yehuda Katz (wycats)

    May 26th, 2010 @ 07:10 AM

  4. José Valim
    José Valim

    David, I could not apply it. Could you please rebase?

    May 26th, 2010 @ 07:50 AM

  5. David Chelimsky
    David Chelimsky

    I forgot there were two commits on that branch. In the previous commit I rearranged the tests in test_case_test. Here are the two commits (in order):

    http://github.com/dchelimsky/rails/commit/44fda04e9a5e2d19a412104b5...

    http://github.com/dchelimsky/rails/commit/53ba21a30fd359744cdee9acd...

    If you want, I can squash them into one commit. If not, they should apply cleanly in that order.

    Obrigado,
    David

    May 26th, 2010 @ 12:05 PM

  6. Repository
    Repository
    • State changed from new to resolved

    (from [e02db06ece7aeecec7c37f5b0e3de7d65c8684e6]) In AV::TC, move protect_against_forgery? from the test_case to the _helper module included in the view.

    • ensures that protect_against_forgery? is present when a helper included in a partial that is rendered by the template under test calls it (which happens in FormTagHelper#extra_tags_for_form, for example).

    [#4700 undefined method `protect_against_forgery?' for #<ActionView::Base:0x10ad1a500> state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/e02db06ece7aeecec7c37f5b0e3de7...

    May 26th, 2010 @ 02:59 PM