From f7abf0c9db61621b3f27061debd7983075cdca61 Mon Sep 17 00:00:00 2001
From: Clemens Kofler
Date: Sun, 27 Jul 2008 16:34:20 -0500
Subject: error_message_on takes an options hash instead of ordered parameters
[#704 state:resolved] Signed-off-by: Joshua Peek
---
.../action_view/helpers/active_record_helper.rb | 46 ++++++++++++++-------
actionpack/lib/action_view/helpers/form_helper.rb | 4 +-
.../test/template/active_record_helper_test.rb | 48 +++++++++++-----------
3 files changed, 58 insertions(+), 40 deletions(-)
diff --git a/actionpack/lib/action_view/helpers/active_record_helper.rb b/actionpack/lib/action_view/helpers/active_record_helper.rb
index 959d8a8563..ff70ce9aae 100644
--- a/actionpack/lib/action_view/helpers/active_record_helper.rb
+++ b/actionpack/lib/action_view/helpers/active_record_helper.rb
@@ -25,7 +25,7 @@ module ActionView
# Returns an entire form with all needed input tags for a specified Active Record object. For example, if @post
# has attributes named +title+ of type +VARCHAR+ and +body+ of type +TEXT+ then
#
- # form("post")
+ # form("post")
#
# would yield a form like the following (modulus formatting):
#
@@ -90,23 +90,41 @@ module ActionView
end
# Returns a string containing the error message attached to the +method+ on the +object+ if one exists.
- # This error message is wrapped in a DIV tag, which can be extended to include a +prepend_text+ and/or +append_text+
- # (to properly explain the error), and a +css_class+ to style it accordingly. +object+ should either be the name of an instance variable or
- # the actual object. As an example, let's say you have a model @post that has an error message on the +title+ attribute:
+ # This error message is wrapped in a DIV tag, which can be extended to include a :prepend_text
+ # and/or :append_text (to properly explain the error), and a :css_class to style it
+ # accordingly. +object+ should either be the name of an instance variable or the actual object. The method can be
+ # passed in either as a string or a symbol.
+ # As an example, let's say you have a model @post that has an error message on the +title+ attribute:
#
# <%= error_message_on "post", "title" %>
# # =>
", error_message_on(:post, :author_name, :css_class => 'differentError', :prepend_text => 'before', :append_text => 'after')
end
def test_error_messages_for_many_objects
@@ -224,10 +224,10 @@ class ActiveRecordHelperTest < ActionView::TestCase
# add the default to put post back in the title
assert_dom_equal %(
2 errors prohibited this post from being saved
There were problems with the following fields:
User email can't be empty
Author name can't be empty
), error_messages_for("user", "post", :object_name => "post")
-
+
# symbols work as well
assert_dom_equal %(
2 errors prohibited this post from being saved
There were problems with the following fields:
User email can't be empty
Author name can't be empty
), error_messages_for(:user, :post, :object_name => :post)
-
+
# any default works too
assert_dom_equal %(
2 errors prohibited this monkey from being saved
There were problems with the following fields:
User email can't be empty
Author name can't be empty
), error_messages_for(:user, :post, :object_name => "monkey")
@@ -242,7 +242,7 @@ class ActiveRecordHelperTest < ActionView::TestCase
message = "Please fix the following fields and resubmit:"
assert_dom_equal %(