diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-08-18 14:21:47 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-18 14:21:47 -0400 |
commit | 99c604f1f9de2f2a6fc3d0aec4f274cb05b48c69 (patch) | |
tree | 7992eb757eda7ae380e4a0f56fd8d5cb443efd36 | |
parent | 4e64a50cc34149925f454d595f131f23cd0b9270 (diff) | |
parent | 53c98196e6cf809f5fdb69396e617fa6509085a3 (diff) | |
download | rails-99c604f1f9de2f2a6fc3d0aec4f274cb05b48c69.tar.gz rails-99c604f1f9de2f2a6fc3d0aec4f274cb05b48c69.tar.bz2 rails-99c604f1f9de2f2a6fc3d0aec4f274cb05b48c69.zip |
Merge pull request #30308 from DNNX/rm-pointless-flatten-and-compact-from-am-errors
Simplify ActiveModel::Errors#generate_message
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index c24ae4e430..971bdd08b1 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -398,21 +398,19 @@ module ActiveModel type = options.delete(:message) if options[:message].is_a?(Symbol) if @base.class.respond_to?(:i18n_scope) - defaults = @base.class.lookup_ancestors.map do |klass| - [ :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.i18n_key}.attributes.#{attribute}.#{type}", - :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.i18n_key}.#{type}" ] + i18n_scope = @base.class.i18n_scope.to_s + defaults = @base.class.lookup_ancestors.flat_map do |klass| + [ :"#{i18n_scope}.errors.models.#{klass.model_name.i18n_key}.attributes.#{attribute}.#{type}", + :"#{i18n_scope}.errors.models.#{klass.model_name.i18n_key}.#{type}" ] end + defaults << :"#{i18n_scope}.errors.messages.#{type}" else defaults = [] end - defaults << :"#{@base.class.i18n_scope}.errors.messages.#{type}" if @base.class.respond_to?(:i18n_scope) defaults << :"errors.attributes.#{attribute}.#{type}" defaults << :"errors.messages.#{type}" - defaults.compact! - defaults.flatten! - key = defaults.shift defaults = options.delete(:message) if options[:message] value = (attribute != :base ? @base.send(:read_attribute_for_validation, attribute) : nil) |