提交 450257c9 编写于 作者: A Aaron Patterson

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

上级 1d9ab88e
......@@ -579,7 +579,12 @@ class InstanceTag #:nodoc:
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 @@ def test_empty
)
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>"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册