aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2014-11-21 13:13:03 -0200
committerSantiago Pastorino <santiago@wyeworks.com>2014-11-21 13:13:03 -0200
commit7e375afba30951b60a3e606ccbfe3f28b0df5e1a (patch)
tree1730c415048d06535d22e32ceca8bad52ce23f96 /actionview
parentf766abd4cf3eb75469d3646cfb6d85e668c619f3 (diff)
parente0e9d5bd8600c01de6b73487bf66046d179c0ed7 (diff)
downloadrails-7e375afba30951b60a3e606ccbfe3f28b0df5e1a.tar.gz
rails-7e375afba30951b60a3e606ccbfe3f28b0df5e1a.tar.bz2
rails-7e375afba30951b60a3e606ccbfe3f28b0df5e1a.zip
Merge pull request #17702 from tgxworld/fix_select_tag_include_blank_false
Fix select_tag generating tag when set to false.
Diffstat (limited to 'actionview')
-rw-r--r--actionview/lib/action_view/helpers/form_tag_helper.rb4
-rw-r--r--actionview/test/template/form_tag_helper_test.rb6
2 files changed, 9 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb
index c0218fd55d..93c04fbec6 100644
--- a/actionview/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionview/lib/action_view/helpers/form_tag_helper.rb
@@ -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)
diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb
index f8fd642809..84a581b107 100644
--- a/actionview/test/template/form_tag_helper_test.rb
+++ b/actionview/test/template/form_tag_helper_test.rb
@@ -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>)