Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix human attribute_name to handle deeply nested attributes #6642

Merged
merged 1 commit into from

2 participants

@kuroda

This is a backport of b0e2fc8 to Rails 3.2.
See #5843 and #3859 also.

@josevalim josevalim merged commit 6b6c1de into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 6, 2012
  1. @kuroda

    Fix human attribute_name to handle deeply nested attributes

    kuroda authored
    This is a back-port of b0e2fc8 to Rails 3.2.
    See #5843 and #3859 also.
This page is out of date. Refresh to see the latest.
View
4 activemodel/lib/active_model/translation.rb
@@ -44,9 +44,9 @@ def lookup_ancestors
# 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|
View
5 activemodel/test/cases/translation_test.rb
@@ -56,6 +56,11 @@ def test_translated_model_attributes_with_attribute_matching_namespaced_model_na
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')
Something went wrong with that request. Please try again.