mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
properly handle lists of lists. Thanks @adrianpike for reporting!
This commit is contained in:
@@ -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])
|
||||
|
||||
@@ -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>"
|
||||
|
||||
Reference in New Issue
Block a user