Created
May 14, 2011 02:34
-
-
Save AquaGeek/971758 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #6273
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From fe79d4b5e22ae1612f6402d5350af7ade500807c Mon Sep 17 00:00:00 2001 | |
From: Alexey Nayden <alexey.nayden@gmail.com> | |
Date: Mon, 24 Jan 2011 02:49:59 +0300 | |
Subject: [PATCH 1/2] [6273] I18n labels for nested attributes test | |
--- | |
actionpack/test/template/form_helper_test.rb | 10 ++++++++++ | |
1 files changed, 10 insertions(+), 0 deletions(-) | |
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb | |
index 2c60096..8764d16 100644 | |
--- a/actionpack/test/template/form_helper_test.rb | |
+++ b/actionpack/test/template/form_helper_test.rb | |
@@ -24,6 +24,9 @@ class FormHelperTest < ActionView::TestCase | |
:label => { | |
:post => { | |
:body => "Write entire text here" | |
+ }, | |
+ :"post[comments_attributes]" => { | |
+ :body => "Add your comment" | |
} | |
} | |
} | |
@@ -140,6 +143,13 @@ class FormHelperTest < ActionView::TestCase | |
I18n.locale = old_locale | |
end | |
+ def test_label_with_locales_and_nested_attributes | |
+ old_locale, I18n.locale = I18n.locale, :label | |
+ assert_dom_equal('<label for="post_comments_attributes_3_body">Add your comment</label>', label("post[comments_attributes][3]", :body)) | |
+ ensure | |
+ I18n.locale = old_locale | |
+ end | |
+ | |
def test_label_with_for_attribute_as_symbol | |
assert_dom_equal('<label for="my_for">Title</label>', label(:post, :title, nil, :for => "my_for")) | |
end | |
-- | |
1.7.3.5 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 5d0300d56315e50e8e6261fcc5ac923170d14739 Mon Sep 17 00:00:00 2001 | |
From: Alexey Nayden <alexey.nayden@gmail.com> | |
Date: Mon, 24 Jan 2011 02:50:23 +0300 | |
Subject: [PATCH 2/2] [6273] I18n labels for nested attributes fix | |
--- | |
actionpack/lib/action_view/helpers/form_helper.rb | 6 +++++- | |
1 files changed, 5 insertions(+), 1 deletions(-) | |
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb | |
index d7b9e0b..7994061 100644 | |
--- a/actionpack/lib/action_view/helpers/form_helper.rb | |
+++ b/actionpack/lib/action_view/helpers/form_helper.rb | |
@@ -894,7 +894,11 @@ module ActionView | |
label_tag(name_and_id["id"], options, &block) | |
else | |
content = if text.blank? | |
- I18n.t("helpers.label.#{object_name}.#{method_name}", :default => "").presence | |
+ # As there're no universal mapping between object_name and I18n YAML file in case | |
+ # of nested attributes we have to manually strip indices from object names, e.g.: | |
+ # object_name is "person[interests_attributes][0]", but YAML should contain only | |
+ # "person[interests_attributes]" and we're removing "[0]" index | |
+ I18n.t("helpers.label.#{object_name}.#{method_name}".gsub(/(\[.*?\])\[\d+\]/, '\1'), :default => "").presence | |
else | |
text.to_s | |
end | |
-- | |
1.7.3.5 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment