From ec4a1e5a3431d7e358af3b957116adcb6bc75518 Mon Sep 17 00:00:00 2001 From: Tom Lea Date: Tue, 26 Aug 2008 11:08:31 +0100 Subject: [PATCH] Made content_tag_for call content_tag in a more DRY way. Fixes issue where calling content_tag_for in a helper caused multiple renders. --- .../lib/action_view/helpers/record_tag_helper.rb | 6 +++--- actionpack/test/template/record_tag_helper_test.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_view/helpers/record_tag_helper.rb b/actionpack/lib/action_view/helpers/record_tag_helper.rb index 9bb2351..0e784c0 100644 --- a/actionpack/lib/action_view/helpers/record_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/record_tag_helper.rb @@ -49,9 +49,9 @@ module ActionView # def content_tag_for(tag_name, record, *args, &block) prefix = args.first.is_a?(Hash) ? nil : args.shift - options = args.first.is_a?(Hash) ? args.shift : {} - concat content_tag(tag_name, capture(&block), - options.merge({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) })) + options = args.first.is_a?(Hash) ? args.shift.dup : {} + options.merge!({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) }) + content_tag(tag_name, options, &block) end end end diff --git a/actionpack/test/template/record_tag_helper_test.rb b/actionpack/test/template/record_tag_helper_test.rb index 34a200b..67aa047 100644 --- a/actionpack/test/template/record_tag_helper_test.rb +++ b/actionpack/test/template/record_tag_helper_test.rb @@ -34,6 +34,14 @@ class RecordTagHelperTest < ActionView::TestCase assert_dom_equal expected, actual end + def test_block_not_in_erb_multiple_calls + expected = %(
#{@post.body}
) + actual = div_for(@post, :class => "bar") { @post.body } + assert_dom_equal expected, actual + actual = div_for(@post, :class => "bar") { @post.body } + assert_dom_equal expected, actual + end + def test_block_works_with_content_tag_for_in_erb __in_erb_template = '' expected = %(#{@post.body}) -- 1.5.2.4