aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-04-01 04:45:10 -0700
committerJosé Valim <jose.valim@gmail.com>2012-04-01 04:45:10 -0700
commiteb154c529991ed77cd13035e6582178156ba9b32 (patch)
tree8df387d41b9e9f85144bb68b301fbf1faeb3f420
parent9228aa6f50f943193befc3ca7612d5bbda287c86 (diff)
parent806f4d8af078884db3b68facb4c04560d449b9eb (diff)
downloadrails-eb154c529991ed77cd13035e6582178156ba9b32.tar.gz
rails-eb154c529991ed77cd13035e6582178156ba9b32.tar.bz2
rails-eb154c529991ed77cd13035e6582178156ba9b32.zip
Merge pull request #5691 from avakhov/form-label-block
Block version of label should wrapped in field_with_errors in case of error
-rw-r--r--actionpack/lib/action_view/helpers/tags/label.rb6
-rw-r--r--actionpack/test/template/form_helper_test.rb14
2 files changed, 17 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/tags/label.rb b/actionpack/lib/action_view/helpers/tags/label.rb
index 1c8bf063ea..16135fcd5a 100644
--- a/actionpack/lib/action_view/helpers/tags/label.rb
+++ b/actionpack/lib/action_view/helpers/tags/label.rb
@@ -33,7 +33,7 @@ module ActionView
options["for"] = name_and_id["id"] unless options.key?("for")
if block_given?
- @template_object.label_tag(name_and_id["id"], options, &block)
+ content = @template_object.capture(&block)
else
content = if @content.blank?
@object_name.gsub!(/\[(.*)_attributes\]\[\d\]/, '.\1')
@@ -55,9 +55,9 @@ module ActionView
end
content ||= @method_name.humanize
-
- label_tag(name_and_id["id"], content, options)
end
+
+ label_tag(name_and_id["id"], content, options)
end
end
end
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 7b684822fc..f13296a175 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -1080,6 +1080,20 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_form_for_label_error_wrapping_block_and_non_block_versions
+ form_for(@post) do |f|
+ concat f.label(:author_name, 'Name', :class => 'label')
+ concat f.label(:author_name, :class => 'label') { 'Name' }
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123' , 'edit_post', 'patch') do
+ "<div class='field_with_errors'><label for='post_author_name' class='label'>Name</label></div>" +
+ "<div class='field_with_errors'><label for='post_author_name' class='label'>Name</label></div>"
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
def test_form_for_with_namespace
form_for(@post, :namespace => 'namespace') do |f|
concat f.text_field(:title)