From b0e2fc843b555f94a4472ed50b337dc5048c8b8c Mon Sep 17 00:00:00 2001 From: Tsutomu Kuroda Date: Sat, 14 Apr 2012 18:00:54 +0900 Subject: Fix human attribute_name to handle deeply nested attributes When a model nests another model that also nests yet another model using accepts_nested_attributes_for method, its Errors object can have an attribute name with "contacts.addresses.street" style. In this case, the dots within the namespace should be substituted with slashes so that we can provide the translation under the "activemodel.attributes.person/contacts/addresses.street" key. This commit is related to #3859. --- activemodel/lib/active_model/translation.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activemodel/lib/active_model/translation.rb') diff --git a/activemodel/lib/active_model/translation.rb b/activemodel/lib/active_model/translation.rb index 6f0ca92e2a..7a86701f73 100644 --- a/activemodel/lib/active_model/translation.rb +++ b/activemodel/lib/active_model/translation.rb @@ -42,9 +42,9 @@ module ActiveModel # Specify +options+ with additional translating options. def human_attribute_name(attribute, options = {}) options = { :count => 1 }.merge!(options) - parts = attribute.to_s.split(".", 2) + parts = attribute.to_s.split(".") attribute = parts.pop - namespace = parts.pop + namespace = parts.join("/") unless parts.empty? attributes_scope = "#{self.i18n_scope}.attributes" if namespace -- cgit v1.2.3