Skip to content

Commit

Permalink
made error_message_on work by passing in the object name if there is …
Browse files Browse the repository at this point in the history
…no object [#3246 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
hypothetical authored and josevalim committed Apr 10, 2010
1 parent 2cd29f4 commit dae2473
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/form_helper.rb
Expand Up @@ -1042,7 +1042,7 @@ def hidden_field(method, options = {})
end

def error_message_on(method, *args)
@template.error_message_on(@object, method, *args)
@template.error_message_on(@object || @object_name, method, *args)
end

def error_messages(options = {})
Expand Down
16 changes: 16 additions & 0 deletions actionpack/test/template/form_helper_test.rb
Expand Up @@ -1220,6 +1220,22 @@ def test_default_form_builder_no_instance_variable
assert_dom_equal expected, output_buffer

end

def test_default_form_builder_without_object

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

expected = %(<form action='http://www.example.com' method='post'>) +
%(<div class='formError'>can't be empty</div>) +
%(<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>)

assert_dom_equal expected, output_buffer

end

# Perhaps this test should be moved to prototype helper tests.
def test_remote_form_for_with_labelled_builder
Expand Down

0 comments on commit dae2473

Please sign in to comment.