Sha256: dbaccbee5cd4da3392fe38226fe95f8a30f173bfb79bb7880e9c962f647b0842

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 KB

Contents

module ErrorMessagesHelper
  # Render error messages for the given objects. The :message and :header_message options are allowed.
  def error_messages_for(*objects)
    options = objects.extract_options!
    options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
    options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
    messages = objects.compact.map { |o| o.errors.full_messages }.flatten
    unless messages.empty?
      content_tag(:div, :class => "error_messages") do
        list_items = messages.map { |msg| content_tag(:li, msg.html_safe) }
        content_tag(:h2, options[:header_message].html_safe) + content_tag(:p, options[:message].html_safe) + content_tag(:ul, list_items.join.html_safe)
      end
    end
  end

  module FormBuilderAdditions
    def error_messages(options = {})
      @template.error_messages_for(@object, options)
    end
  end
end

ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)

Version data entries

12 entries across 12 versions & 8 rubygems

Version Path
aslon_scaffold-0.0.15 lib/generators/nifty/layout/templates/error_messages_helper.rb
aslon_scaffold-0.0.14 lib/generators/nifty/layout/templates/error_messages_helper.rb
aslon_scaffold-0.0.13 lib/generators/nifty/layout/templates/error_messages_helper.rb
tripper-0.0.3d lib/generators/tripper/layout/templates/error_messages_helper.rb
aslon_scaffold-0.0.12 lib/generators/nifty/layout/templates/error_messages_helper.rb
survey_says-0.0.2 test/dummy/app/helpers/error_messages_helper.rb
bravo-generators-0.1.1 lib/generators/bravo/layout/templates/error_messages_helper.rb
kickoff-0.0.2 lib/generators/kickoff/layout/templates/error_messages_helper.rb
survey_says-0.0.1 test/dummy/app/helpers/error_messages_helper.rb
entropi-bootstrap-rails-0.1.0 lib/generators/bootstrap/layout/templates/error_messages_helper.rb
nifty-generators-improved-0.5 lib/generators/nifty/layout/templates/error_messages_helper.rb
zoo-generators-0.1.0 lib/generators/zoo/layout/templates/error_messages_helper.rb