Skip to content
Browse files

made error_message_on work by passing in the object name if there is …

…no object [#3246 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 2cd29f4 commit dae247316d83c9c2f1b3cc797e0d6fcf98d46f92 @hypothetical hypothetical committed with josevalim Sep 22, 2009
Showing with 17 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_view/helpers/form_helper.rb
  2. +16 −0 actionpack/test/template/form_helper_test.rb
View
2 actionpack/lib/action_view/helpers/form_helper.rb
@@ -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 = {})
View
16 actionpack/test/template/form_helper_test.rb
@@ -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

0 comments on commit dae2473

Please sign in to comment.
Something went wrong with that request. Please try again.