mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixes a bug where error_messages_for was returning an empty div [#4048 state:resolved] (ht: Geoff Garside)
This commit is contained in:
parent
418e5fc279
commit
0a352056a4
2 changed files with 5 additions and 1 deletions
|
@ -127,7 +127,7 @@ module ActionView
|
|||
object = convert_to_model(object)
|
||||
|
||||
if (obj = (object.respond_to?(:errors) ? object : instance_variable_get("@#{object}"))) &&
|
||||
(errors = obj.errors[method])
|
||||
(errors = obj.errors[method]).presence
|
||||
content_tag("div",
|
||||
"#{options[:prepend_text]}#{ERB::Util.h(errors.first)}#{options[:append_text]}".html_safe,
|
||||
:class => options[:css_class]
|
||||
|
|
|
@ -266,6 +266,10 @@ class ActiveModelHelperTest < ActionView::TestCase
|
|||
assert_dom_equal "<div class=\"differentError\">beforecan't be emptyafter</div>", error_message_on(:post, :author_name, :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after')
|
||||
end
|
||||
|
||||
def test_error_message_on_handles_empty_errors
|
||||
assert_equal "", error_message_on(@post, :tag)
|
||||
end
|
||||
|
||||
def test_error_messages_for_many_objects
|
||||
assert_dom_equal %(<div class="errorExplanation" id="errorExplanation"><h2>2 errors 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><li>User email can't be empty</li></ul></div>), error_messages_for("post", "user")
|
||||
|
||||
|
|
Loading…
Reference in a new issue