aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-06 20:22:42 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-06 20:22:42 -0200
commit4afb55f4e77d035826c0fba1983386aa03cda90e (patch)
tree29f5023dd29b18b0941fcbc9b9025e7e91b9b309
parent254693a39c73b6fc9ad71b47b4d652e8738bec12 (diff)
parentbe0875f4580749c2c5ad84086f2e890ddeba7de8 (diff)
downloadrails-4afb55f4e77d035826c0fba1983386aa03cda90e.tar.gz
rails-4afb55f4e77d035826c0fba1983386aa03cda90e.tar.bz2
rails-4afb55f4e77d035826c0fba1983386aa03cda90e.zip
Merge pull request #18834 from mfazekas/fix-i18-for-openstruct
Fixed undefined method `i18n_key' for nil:NilClass for labels in non AR ...
-rw-r--r--actionview/lib/action_view/helpers/tags/translator.rb2
-rw-r--r--actionview/test/template/form_helper_test.rb12
2 files changed, 13 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/tags/translator.rb b/actionview/lib/action_view/helpers/tags/translator.rb
index 829679851c..e70fe024e8 100644
--- a/actionview/lib/action_view/helpers/tags/translator.rb
+++ b/actionview/lib/action_view/helpers/tags/translator.rb
@@ -6,7 +6,7 @@ module ActionView
@object_name = object_name.gsub(/\[(.*)_attributes\]\[\d+\]/, '.\1')
@method_and_value = method_and_value
@scope = scope
- @model = object.respond_to?(:to_model) ? object.to_model : object
+ @model = object.respond_to?(:to_model) ? object.to_model : nil
end
def translate
diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb
index 1ed4fbafcf..4e336bea63 100644
--- a/actionview/test/template/form_helper_test.rb
+++ b/actionview/test/template/form_helper_test.rb
@@ -259,6 +259,18 @@ class FormHelperTest < ActionView::TestCase
end
end
+ def test_label_with_non_active_record_object
+ form_for(OpenStruct.new(name:'ok'), as: 'person', url: 'an_url', html: { id: 'create-person' }) do |f|
+ f.label(:name)
+ end
+
+ expected = whole_form("an_url", "create-person", "new_person", method: "post") do
+ '<label for="person_name">Name</label>'
+ end
+
+ assert_dom_equal expected, output_buffer
+ 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