aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2006-12-27 20:46:12 +0000
committerMichael Koziarski <michael@koziarski.com>2006-12-27 20:46:12 +0000
commit810d0ade2bb04464fbbd5497b4cc092ed80fc53a (patch)
treeefd047279ddcbbfaaa5288826f8b82d045083fb9 /actionpack/lib/action_view
parent3b4450bb8043eca6ca0d423263e598c70c50f440 (diff)
downloadrails-810d0ade2bb04464fbbd5497b4cc092ed80fc53a.tar.gz
rails-810d0ade2bb04464fbbd5497b4cc092ed80fc53a.tar.bz2
rails-810d0ade2bb04464fbbd5497b4cc092ed80fc53a.zip
Make error_message_on handle nil objects. [dan]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5799 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/active_record_helper.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/active_record_helper.rb b/actionpack/lib/action_view/helpers/active_record_helper.rb
index a001ae5e65..fff22d2688 100644
--- a/actionpack/lib/action_view/helpers/active_record_helper.rb
+++ b/actionpack/lib/action_view/helpers/active_record_helper.rb
@@ -85,8 +85,10 @@ module ActionView
# <%= error_message_on "post", "title", "Title simply ", " (or it won't work)", "inputError" %> =>
# <div class="inputError">Title simply can't be empty (or it won't work)</div>
def error_message_on(object, method, prepend_text = "", append_text = "", css_class = "formError")
- if errors = instance_variable_get("@#{object}").errors.on(method)
+ if object = instance_variable_get("@#{object}") && errors = object.errors.on(method)
content_tag("div", "#{prepend_text}#{errors.is_a?(Array) ? errors.first : errors}#{append_text}", :class => css_class)
+ else
+ ''
end
end