diff options
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/active_record_helper.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/active_record_helper.rb b/actionpack/lib/action_view/helpers/active_record_helper.rb index c9d2c095bf..a7bfb77db3 100644 --- a/actionpack/lib/action_view/helpers/active_record_helper.rb +++ b/actionpack/lib/action_view/helpers/active_record_helper.rb @@ -120,13 +120,23 @@ module ActionView objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact count = objects.inject(0) {|sum, object| sum + object.errors.count } unless count.zero? + html = {} + [:id, :class].each do |key| + if options.include?(key) + value = options[key] + html[key] = value unless value.blank? + else + html[key] = 'errorExplanation' + end + end header_message = "#{pluralize(count, 'error')} prohibited this #{(options[:object_name] || params.first).to_s.gsub('_', ' ')} from being saved" 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), - :id => options[:id] || 'errorExplanation', :class => options[:class] || 'errorExplanation') + content_tag(:p, 'There were problems with the following fields:') << + content_tag(:ul, error_messages), + html + ) else '' end |