mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
make error_messages_for return "" for nil objects
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3438 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
363b79f942
commit
e3898491f2
3 changed files with 9 additions and 1 deletions
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* allow nil objects for error_messages_for [Michael Koziarski]
|
||||||
|
|
||||||
* Refactor human_size to exclude decimal place if it is zero. [Marcel Molina Jr.]
|
* Refactor human_size to exclude decimal place if it is zero. [Marcel Molina Jr.]
|
||||||
|
|
||||||
* Update to Prototype 1.5.0_pre0 [Sam Stephenson]
|
* Update to Prototype 1.5.0_pre0 [Sam Stephenson]
|
||||||
|
|
|
@ -103,7 +103,7 @@ module ActionView
|
||||||
def error_messages_for(object_name, options = {})
|
def error_messages_for(object_name, options = {})
|
||||||
options = options.symbolize_keys
|
options = options.symbolize_keys
|
||||||
object = instance_variable_get("@#{object_name}")
|
object = instance_variable_get("@#{object_name}")
|
||||||
unless object.errors.empty?
|
if object && !object.errors.empty?
|
||||||
content_tag("div",
|
content_tag("div",
|
||||||
content_tag(
|
content_tag(
|
||||||
options[:header_tag] || "h2",
|
options[:header_tag] || "h2",
|
||||||
|
@ -113,6 +113,8 @@ module ActionView
|
||||||
content_tag("ul", object.errors.full_messages.collect { |msg| content_tag("li", msg) }),
|
content_tag("ul", object.errors.full_messages.collect { |msg| content_tag("li", msg) }),
|
||||||
"id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
|
"id" => options[:id] || "errorExplanation", "class" => options[:class] || "errorExplanation"
|
||||||
)
|
)
|
||||||
|
else
|
||||||
|
""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,10 @@ class ActiveRecordHelperTest < Test::Unit::TestCase
|
||||||
assert_dom_equal %(<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>), error_messages_for("post")
|
assert_dom_equal %(<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>), error_messages_for("post")
|
||||||
assert_equal %(<div class="errorDeathByClass" id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
|
assert_equal %(<div class="errorDeathByClass" id="errorDeathById"><h1>1 error prohibited this post from being saved</h1><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>), error_messages_for("post", :class => "errorDeathByClass", :id => "errorDeathById", :header_tag => "h1")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_error_messages_for_handles_nil
|
||||||
|
assert_equal "", error_messages_for("notthere")
|
||||||
|
end
|
||||||
|
|
||||||
def test_form_with_string_multipart
|
def test_form_with_string_multipart
|
||||||
assert_dom_equal(
|
assert_dom_equal(
|
||||||
|
|
Loading…
Reference in a new issue