Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

allow options hash with string keys in content_tag_for helper #5704

Closed
wants to merge 1 commit into from

3 participants

@lest

No description provided.

@rafaelfranca
Owner

Why we need to allows this? The normal use is with symbol keys

@josevalim
Owner

Yeah, :-1: from here also. People should not expect all methods to accept both symbols and strings as hash keys.

@lest lest closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 actionpack/lib/action_view/helpers/record_tag_helper.rb
@@ -93,8 +93,9 @@ def content_tag_for(tag_name, single_or_multiple_records, prefix = nil, options
# Called by <tt>content_tag_for</tt> internally to render a content tag
# for each record.
def content_tag_for_single_record(tag_name, record, prefix, options, &block)
- options = options ? options.dup : {}
- options.merge!(:class => "#{dom_class(record, prefix)} #{options[:class]}".rstrip, :id => dom_id(record, prefix))
+ options = options ? options.symbolize_keys : {}
+ options[:class] = "#{dom_class(record, prefix)} #{options[:class]}".rstrip
+ options[:id] = dom_id(record, prefix)
content = block.arity == 0 ? capture(&block) : capture(record, &block)
content_tag(tag_name, content, options)
View
6 actionpack/test/template/record_tag_helper_test.rb
@@ -100,4 +100,10 @@ def test_content_tag_for_does_not_change_options_hash
content_tag_for(:li, @post, options) { }
assert_equal({ :class => "important" }, options)
end
+
+ def test_content_tag_for_with_string_options
+ expected = %(<li class="record_tag_post custom" id="record_tag_post_45"></li>)
+ actual = content_tag_for(:li, @post, 'class' => 'custom') { }
+ assert_dom_equal expected, actual
+ end
end
Something went wrong with that request. Please try again.