Class: ActiveModel::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/russian/active_model_ext/custom_error_message.rb

Instance Method Summary collapse

Instance Method Details

#full_messagesObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/russian/active_model_ext/custom_error_message.rb', line 42

def full_messages
  full_messages = []

  each do |attribute, messages|
    messages = Array.wrap(messages)
    next if messages.empty?

    if attribute == :base
      messages.each {|m| full_messages << m }
    else
      attr_name = attribute.to_s.gsub('.', '_').humanize
      attr_name = @base.class.human_attribute_name(attribute, :default => attr_name)
      options = { :attribute => attr_name, :default => "%{attribute} %{message}" }

      messages.each do |m|
        if m =~ /^\^/
          full_messages << m[1..-1]
        else
          full_messages << I18n.t(:errors.format", options.merge(:message => m))
        end
      end
    end
  end

  full_messages
end