diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2012-06-06 00:18:59 -0700 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2012-06-06 00:18:59 -0700 |
commit | 6b6c1de9f96d27af73371b1595c4b9ff76bb59bc (patch) | |
tree | 03de1881f9b541a357ee3754c5eb952a5665c44f /activemodel | |
parent | 3cba6eee66a4c25b93839ea6fd1da08d7780f2de (diff) | |
parent | 029936efbe7318e9146c22c6609e1571c7abb0c1 (diff) | |
download | rails-6b6c1de9f96d27af73371b1595c4b9ff76bb59bc.tar.gz rails-6b6c1de9f96d27af73371b1595c4b9ff76bb59bc.tar.bz2 rails-6b6c1de9f96d27af73371b1595c4b9ff76bb59bc.zip |
Merge pull request #6642 from kuroda/3-2-activemodel-translation-patch
Fix human attribute_name to handle deeply nested attributes
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/translation.rb | 4 | ||||
-rw-r--r-- | activemodel/test/cases/translation_test.rb | 5 |
2 files changed, 7 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/translation.rb b/activemodel/lib/active_model/translation.rb index 02b7c54d61..e560d9e2cf 100644 --- a/activemodel/lib/active_model/translation.rb +++ b/activemodel/lib/active_model/translation.rb @@ -44,9 +44,9 @@ module ActiveModel # Specify +options+ with additional translating options. def human_attribute_name(attribute, options = {}) defaults = [] - parts = attribute.to_s.split(".", 2) + parts = attribute.to_s.split(".") attribute = parts.pop - namespace = parts.pop + namespace = parts.join("/") unless parts.empty? if namespace lookup_ancestors.each do |klass| diff --git a/activemodel/test/cases/translation_test.rb b/activemodel/test/cases/translation_test.rb index 54e86d48db..6bf92359c5 100644 --- a/activemodel/test/cases/translation_test.rb +++ b/activemodel/test/cases/translation_test.rb @@ -56,6 +56,11 @@ class ActiveModelI18nTests < ActiveModel::TestCase assert_equal 'person gender attribute', Person::Gender.human_attribute_name('attribute') end + def test_translated_deeply_nested_model_attributes + I18n.backend.store_translations 'en', :activemodel => {:attributes => {:"person/contacts/addresses" => {:street => 'Deeply Nested Address Street'}}} + assert_equal 'Deeply Nested Address Street', Person.human_attribute_name('contacts.addresses.street') + end + def test_translated_nested_model_attributes I18n.backend.store_translations 'en', :activemodel => {:attributes => {:"person/addresses" => {:street => 'Person Address Street'}}} assert_equal 'Person Address Street', Person.human_attribute_name('addresses.street') |