1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

properly handle lists of lists. Thanks @adrianpike for reporting!

This commit is contained in:
Aaron Patterson 2011-10-25 17:44:17 -07:00
parent 1d9ab88ee6
commit 450257c95b
2 changed files with 15 additions and 1 deletions

View file

@ -579,7 +579,12 @@ module ActionView
def to_select_tag(choices, options, html_options)
selected_value = options.has_key?(:selected) ? options[:selected] : value(object)
if !choices.empty? && Array === choices.first
# Grouped choices look like this:
#
# [nil, []]
# { nil => [] }
#
if !choices.empty? && choices.first.last.respond_to?(:each)
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])

View file

@ -596,6 +596,15 @@ class FormOptionsHelperTest < ActionView::TestCase
)
end
def test_list_of_lists
@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<option value=\"number\">Number</option>\n<option value=\"text\">Text</option>\n<option value=\"boolean\">Yes/No</option></select>",
select("post", "category", [["Number", "number"], ["Text", "text"], ["Yes/No", "boolean"]], :prompt => true, :include_blank => true)
)
end
def test_select_with_selected_value
@post = Post.new
@post.category = "<mus>"