Module: ErrorMessagesHelper

Defined in:
app/helpers/error_messages_helper.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Defined Under Namespace

Modules: FormBuilderAdditions

Instance Method Summary collapse

Instance Method Details

#error_messages_for(*objects) ⇒ Object

Render error messages for the given objects. The :message and :header_message options are allowed.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/error_messages_helper.rb', line 7

def error_messages_for(*objects)
  options = objects.extract_options!
  options[:header_message] ||= I18n.t('error_messages.helper.invalid_fields')
  options[:message] ||= I18n.t('error_messages.helper.correct_the_following_errors_and_try_again')
  messages = objects.compact.map { |o| o.errors.full_messages }.flatten
  unless messages.empty?
    (:div, :class => "error_messages") do
      list_items = messages.map { |msg| (:li, msg) }
      (:h2, options[:header_message]) + (:p, options[:message]) + (:ul, list_items.join.html_safe)
    end
  end
end