Module | ActionView::Helpers::ActiveRecordHelper
In: | vendor/plugins/brazilian-rails/lib/action_view_portuguese.rb

### Methods

error_messages_for

### Public Instance methods

error_messages_for(*params)

[Source]

        # File vendor/plugins/brazilian-rails/lib/action_view_portuguese.rb, line 2
     2:   def error_messages_for(*params)
     3:     options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {}
     4:     objects = params.collect { |object_name| instance_variable_get('@'+object_name.to_s()) }
     5:     objects.compact!
     6:     count   = objects.inject(0) {|sum, object| sum + object.errors.count }
     7:     unless count.zero?
     8:       html = {}
     9:       [:id, :class].each do |key|
    10:         if options.include?(key)
    11:           value = options[key]
    12:           html[key] = value unless value.blank?
    13:         else
    14:           html[key] = 'errorExplanation'
    15:         end
    16:       end
    17:       header_message = "#{pluralize(count, 'erro')} para #{(options[:object_name] || params.first).to_s.gsub('_', ' ')}"
    18:       error_messages = objects.map { |object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } }
    19:       content_tag(:div,
    20:       content_tag(options[:header_tag] || :h2, header_message) <<
    21:       content_tag(:p, 'Foram detectados os seguintes erros:') <<
    22:       content_tag(:ul, error_messages),
    23:       html
    24:       )
    25:     else
    26:       ''
    27:     end
    28:   end

[Validate]