aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/active_record_helper.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-10-14 02:59:32 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-10-14 02:59:32 +0000
commit01cfda7cf280b5050b4431790702d63a956190c2 (patch)
treef9ad17e3e8f6f96e51fb614ba8d1eb58babf835e /actionpack/lib/action_view/helpers/active_record_helper.rb
parent16796dc35f08ce567a0c4102b126527996c3b784 (diff)
downloadrails-01cfda7cf280b5050b4431790702d63a956190c2.tar.gz
rails-01cfda7cf280b5050b4431790702d63a956190c2.tar.bz2
rails-01cfda7cf280b5050b4431790702d63a956190c2.zip
error_messages_for also takes :message and :header_message options which defaults to the old "There were problems with the following fields:" and "<count> errors prohibited this <object_name> from being saved". Closes #8270.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7870 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/active_record_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/active_record_helper.rb26
1 files changed, 14 insertions, 12 deletions
diff --git a/actionpack/lib/action_view/helpers/active_record_helper.rb b/actionpack/lib/action_view/helpers/active_record_helper.rb
index e2e35cb0bd..a55c4966a3 100644
--- a/actionpack/lib/action_view/helpers/active_record_helper.rb
+++ b/actionpack/lib/action_view/helpers/active_record_helper.rb
@@ -106,11 +106,10 @@ module ActionView
# * <tt>header_tag</tt> - Used for the header of the error div (default: h2)
# * <tt>id</tt> - The id of the error div (default: errorExplanation)
# * <tt>class</tt> - The class of the error div (default: errorExplanation)
- # * <tt>object</tt> - The object (or array of objects) for which to display errors,
- # if you need to escape the instance variable convention
- # * <tt>object_name</tt> - The object name to use in the header, or
- # any text that you prefer. If <tt>object_name</tt> is not set, the name of
- # the first object will be used.
+ # * <tt>object</tt> - The object (or array of objects) for which to display errors, if you need to escape the instance variable convention
+ # * <tt>object_name</tt> - The object name to use in the header, or any text that you prefer. If <tt>object_name</tt> is not set, the name of the first object will be used.
+ # * <tt>header_message</tt> - The message in the header of the error div. Pass +nil+ or an empty string to avoid the header message altogether. (default: X errors prohibited this object from being saved)
+ # * <tt>message</tt> - The explanation message after the header message and before the error list. Pass +nil+ or an empty string to avoid the explanation message altogether. (default: There were problems with the following fields:)
#
# To specify the display for one object, you simply provide its name as a parameter. For example, for the +User+ model:
#
@@ -147,14 +146,17 @@ module ActionView
html[key] = 'errorExplanation'
end
end
- header_message = "#{pluralize(count, 'error')} prohibited this #{(options[:object_name] || params.first).to_s.gsub('_', ' ')} from being saved"
+ options[:object_name] ||= params.first
+ options[:header_message] = "#{pluralize(count, 'error')} prohibited this #{options[:object_name].to_s.gsub('_', ' ')} from being saved" unless options.include?(:header_message)
+ options[:message] ||= 'There were problems with the following fields:' unless options.include?(:message)
error_messages = objects.map {|object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } }
- content_tag(:div,
- content_tag(options[:header_tag] || :h2, header_message) <<
- content_tag(:p, 'There were problems with the following fields:') <<
- content_tag(:ul, error_messages),
- html
- )
+
+ contents = ''
+ contents << content_tag(options[:header_tag] || :h2, options[:header_message]) unless options[:header_message].blank?
+ contents << content_tag(:p, options[:message]) unless options[:message].blank?
+ contents << content_tag(:ul, error_messages)
+
+ content_tag(:div, contents, html)
else
''
end