diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-10-07 16:56:18 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-10-07 16:56:18 -0700 |
commit | 7f64e472772293a3a5bbf4a435d937dabd98ed92 (patch) | |
tree | f7791372136a52d4ddd13cf696040fad074e2c3d | |
parent | d2db917841cacbdd6320460fd6fa3d07cd972139 (diff) | |
download | rails-7f64e472772293a3a5bbf4a435d937dabd98ed92.tar.gz rails-7f64e472772293a3a5bbf4a435d937dabd98ed92.tar.bz2 rails-7f64e472772293a3a5bbf4a435d937dabd98ed92.zip |
just check to see that the first item in the list is an array
-rw-r--r-- | actionpack/lib/action_view/helpers/form_options_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_options_helper_test.rb | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index c677257d60..d636702111 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -579,7 +579,7 @@ module ActionView def to_select_tag(choices, options, html_options) selected_value = options.has_key?(:selected) ? options[:selected] : value(object) - if !choices.empty? && choices.try(:first).try(:second).respond_to?(:each) + if !choices.empty? && Array === choices.first option_tags = grouped_options_for_select(choices, :selected => selected_value, :disabled => options[:disabled]) else option_tags = options_for_select(choices, :selected => selected_value, :disabled => options[:disabled]) diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index 6aea991f7c..d3e0cc41a9 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -587,6 +587,15 @@ class FormOptionsHelperTest < ActionView::TestCase ) end + def test_empty + @post = Post.new + @post.category = "" + assert_dom_equal( + "<select id=\"post_category\" name=\"post[category]\"><option value=\"\">Please select</option>\n<option value=\"\"></option>\n</select>", + select("post", "category", [], :prompt => true, :include_blank => true) + ) + end + def test_select_with_selected_value @post = Post.new @post.category = "<mus>" |