From 0b54641878a9cee450170135ca0c43ddbb4cb09f Mon Sep 17 00:00:00 2001 From: Martin Larochelle Date: Tue, 14 Aug 2018 11:52:26 -0400 Subject: `ActiveModel.full_message` interaction with `index_errors` --- activemodel/lib/active_model/errors.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index edc30ee64d..5138a07b71 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -379,9 +379,11 @@ module ActiveModel # * errors.format def full_message(attribute, message) return message if attribute == :base + attribute = attribute.to_s if self.class.i18n_full_message && @base.class.respond_to?(:i18n_scope) - parts = attribute.to_s.split(".") + 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" @@ -410,8 +412,9 @@ module ActiveModel defaults << :"errors.format" defaults << "%{attribute} %{message}" - attr_name = attribute.to_s.tr(".", "_").humanize - attr_name = @base.class.human_attribute_name(attribute, default: attr_name) + attr_name = attribute.tr(".", "_").humanize + attr_name = @base.class.human_attribute_name(attribute.to_sym, default: attr_name) + I18n.t(defaults.shift, default: defaults, attribute: attr_name, -- cgit v1.2.3 From 8d2f3179e6f312b34a2bacf36bc74f9c24e751bd Mon Sep 17 00:00:00 2001 From: Martin Larochelle Date: Thu, 16 Aug 2018 11:07:56 -0400 Subject: Call human_attribute_name with a string instead of a symbole --- activemodel/lib/active_model/errors.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 5138a07b71..af94d52d45 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -413,7 +413,7 @@ module ActiveModel defaults << "%{attribute} %{message}" attr_name = attribute.tr(".", "_").humanize - attr_name = @base.class.human_attribute_name(attribute.to_sym, default: attr_name) + attr_name = @base.class.human_attribute_name(attribute, default: attr_name) I18n.t(defaults.shift, default: defaults, -- cgit v1.2.3