Fix select_tag generating tag when set to false.

Fixes https://github.com/rails/rails/issues/17701.
This commit is contained in:
Guo Xiang Tan 2014-11-21 17:44:24 +08:00
parent 8ffc8da713
commit e0e9d5bd86
2 changed files with 9 additions and 1 deletions

View File

@ -140,7 +140,9 @@ module ActionView
include_blank = ''
end
option_tags = content_tag(:option, include_blank, value: '').safe_concat(option_tags)
if include_blank
option_tags = content_tag(:option, include_blank, value: '').safe_concat(option_tags)
end
end
if prompt = options.delete(:prompt)

View File

@ -232,6 +232,12 @@ class FormTagHelperTest < ActionView::TestCase
assert_dom_equal expected, actual
end
def test_select_tag_with_include_blank_false
actual = select_tag "places", "<option>Home</option><option>Work</option><option>Pub</option>".html_safe, include_blank: false
expected = %(<select id="places" name="places"><option>Home</option><option>Work</option><option>Pub</option></select>)
assert_dom_equal expected, actual
end
def test_select_tag_with_include_blank_string
actual = select_tag "places", "<option>Home</option><option>Work</option><option>Pub</option>".html_safe, include_blank: 'Choose'
expected = %(<select id="places" name="places"><option value="">Choose</option><option>Home</option><option>Work</option><option>Pub</option></select>)