Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make content_tag_for work without block

This is version of #8640 for master
  • Loading branch information...
commit 7e2ef18b51152ed846f0ee2888bdd63d30c6f6c4 1 parent 51ab77e
Rafael Mendonça França rafaelfranca authored
4 actionpack/CHANGELOG.md
View
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
+* Fix a bug in `content_tag_for` that prevents it for work without a block.
+
+ *Jasl*
+
* Change the stylesheet of exception pages for development mode.
Additionally display also the line of code and fragment that raised
the exception in all exceptions pages.
6 actionpack/lib/action_view/helpers/record_tag_helper.rb
View
@@ -95,7 +95,11 @@ def content_tag_for_single_record(tag_name, record, prefix, options, &block)
options[:class] = "#{dom_class(record, prefix)} #{options[:class]}".rstrip
options[:id] = dom_id(record, prefix)
- content_tag(tag_name, capture(record, &block), options)
+ if block_given?
+ content_tag(tag_name, capture(record, &block), options)
+ else
+ content_tag(tag_name, "", options)
+ end
end
end
end
8 actionpack/test/template/record_tag_helper_test.rb
View
@@ -75,6 +75,14 @@ def test_content_tag_for_collection
assert_dom_equal expected, actual
end
+ def test_content_tag_for_collection_without_given_block
+ post_1 = RecordTagPost.new.tap { |post| post.id = 101; post.body = "Hello!" }
+ post_2 = RecordTagPost.new.tap { |post| post.id = 102; post.body = "World!" }
+ expected = %(<li class="record_tag_post" id="record_tag_post_101"></li>\n<li class="record_tag_post" id="record_tag_post_102"></li>)
+ actual = content_tag_for(:li, [post_1, post_2])
+ assert_dom_equal expected, actual
+ end
+
def test_div_for_collection
post_1 = RecordTagPost.new { |post| post.id = 101; post.body = "Hello!" }
post_2 = RecordTagPost.new { |post| post.id = 102; post.body = "World!" }
Please sign in to comment.
Something went wrong with that request. Please try again.