Method: ActiveModel::Error.full_message
- Defined in:
- activemodel/lib/active_model/error.rb
.full_message(attribute, message, base) ⇒ Object
:nodoc:
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'activemodel/lib/active_model/error.rb', line 15 def self.(attribute, , base) # :nodoc: return if attribute == :base base_class = base.class attribute = attribute.to_s if && base_class.respond_to?(:i18n_scope) attribute = attribute.remove(/\[\d+\]/) parts = attribute.split(".") attribute_name = parts.pop namespace = parts.join("/") unless parts.empty? attributes_scope = "#{base_class.i18n_scope}.errors.models" if namespace defaults = base_class.lookup_ancestors.map do |klass| [ :"#{attributes_scope}.#{klass.model_name.i18n_key}/#{namespace}.attributes.#{attribute_name}.format", :"#{attributes_scope}.#{klass.model_name.i18n_key}/#{namespace}.format", ] end else defaults = base_class.lookup_ancestors.map do |klass| [ :"#{attributes_scope}.#{klass.model_name.i18n_key}.attributes.#{attribute_name}.format", :"#{attributes_scope}.#{klass.model_name.i18n_key}.format", ] end end defaults.flatten! else defaults = [] end defaults << :"errors.format" defaults << "%{attribute} %{message}" attr_name = attribute.remove(/\.base\z/).tr(".", "_").humanize attr_name = base_class.human_attribute_name(attribute, { default: attr_name, base: base, }) I18n.t(defaults.shift, default: defaults, attribute: attr_name, message: ) end |