From dff19f7be2584d9eaa869de14a919aa70d029d92 Mon Sep 17 00:00:00 2001 From: Tsutomu Kuroda Date: Mon, 5 Dec 2011 22:57:47 +0900 Subject: Fix human_attribute_name to handle names with dots Nested I18n namespace lookup under activerecord.models is deprecated now (c19bd4f). But when a model uses accepts_nested_attributes_for, its Errors object can have an attribute name with "addresses.street" style. In this case, the dots should be substituted with slashes so that we can provide the translation under the "activemodel.attributes.person.addresses/street" key. --- activemodel/lib/active_model/translation.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'activemodel/lib') diff --git a/activemodel/lib/active_model/translation.rb b/activemodel/lib/active_model/translation.rb index 6d64c81b5f..d776fe0ce6 100644 --- a/activemodel/lib/active_model/translation.rb +++ b/activemodel/lib/active_model/translation.rb @@ -43,8 +43,12 @@ module ActiveModel # # Specify +options+ with additional translating options. def human_attribute_name(attribute, options = {}) - defaults = lookup_ancestors.map do |klass| - :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute}" + defaults = [] + lookup_ancestors.each do |klass| + if attribute.match(/\./) + defaults << :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute.gsub(/\./, '/')}" + end + defaults << :"#{self.i18n_scope}.attributes.#{klass.model_name.i18n_key}.#{attribute}" end defaults << :"attributes.#{attribute}" -- cgit v1.2.3