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] error_message_on does not display error message when form builder is not passed object

#3246

When form_for is invoked using a name and not an object, error_message_on returns an empty string instead of an error message.

    
form_for(:post) do |f|
   concat f.error_message_on('author_name')
   concat f.error_messages
end

Results in:


<form action='http://www.example.com' method='post'>
  <div class="errorExplanation" id="errorExplanation">
    <h2>1 error prohibited this post from being saved</h2>
    <p>There were problems with the following fields:</p>
    <ul><li>Author name can't be empty</li></ul>
  </div>
</form>

This patch will pass in the @object_name if there is no @object.

Reported by Lachlan Sylvester · September 22nd, 2009 @ 10:46 AM

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

Activity

  1. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from 2-3-stable, error_message_on, formbuilder to 2-3-stable, bugmash, error_message_on, formbuilder

    September 25th, 2009 @ 11:53 AM

  2. John Guenin
    John Guenin

    +1 verified bug & patch. Applies cleanly to master & 2-3-stable. All tests pass.

    Nice job, Lachlan :)

    September 26th, 2009 @ 11:06 PM

  3. sr.iniv.t
    sr.iniv.t

    +1 verified.

    The patch applies cleanly on master and 2-3-stable and all tests pass.

    September 27th, 2009 @ 07:41 AM

  4. Elad Meidar
    Elad Meidar

    +1 verified and patch applies on both 2-3-stable and master. maybe @object_name.to_s might also give you the option to use f.error_messages_for(:author_name)

    September 27th, 2009 @ 07:48 AM

  5. CancelProfileIsBroken
    CancelProfileIsBroken
    • Tag changed from 2-3-stable, bugmash, error_message_on, formbuilder to 2-3-stable, bugmash-review, error_message_on, formbuilder

    September 27th, 2009 @ 12:10 PM

  6. Repository
    Repository
    • State changed from new to resolved

    April 10th, 2010 @ 01:03 PM

  7. Rizwan Reza
    Rizwan Reza
    • Tag changed from 2-3-stable, bugmash-review, error_message_on, formbuilder to 2-3-stable, error_message_on, formbuilder

    May 15th, 2010 @ 06:37 PM