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:
parent
1d9ab88ee6
commit
450257c95b
2 changed files with 15 additions and 1 deletions
|
@ -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>"
|
||||
|
|
Loading…
Reference in a new issue