提交 0778290b 编写于 作者: V Vasiliy Ermolovich

options_from_collection_for_select helper takes html attributes

as the last element of the array
上级 2a07db71
## Rails 4.0.0 (unreleased) ##
* Element of the collection for `options_from_collection_for_select` helper can
optionally contain html attributes as the last element of the array as
`options_for_select` helper.
*Vasiliy Ermolovich*
* Fix explicit names on multiple file fields. If a file field tag has
the multiple option, it is turned into an array field (appending `[]`),
......
......@@ -380,7 +380,7 @@ def options_for_select(container, selected = nil)
# should produce the desired results.
def options_from_collection_for_select(collection, value_method, text_method, selected = nil)
options = collection.map do |element|
[value_for_collection(element, text_method), value_for_collection(element, value_method)]
[value_for_collection(element, text_method), value_for_collection(element, value_method), option_html_attributes(element)]
end
selected, disabled = extract_selected_and_disabled(selected)
select_deselect = {
......
......@@ -100,6 +100,13 @@ def test_collection_options_with_proc_for_text_method
)
end
def test_collection_options_with_element_attributes
assert_dom_equal(
"<option value=\"USA\" class=\"bold\">USA</option>",
options_from_collection_for_select([[ "USA", "USA", { :class => 'bold' } ]], :first, :second)
)
end
def test_string_options_for_select
options = "<option value=\"Denmark\">Denmark</option><option value=\"USA\">USA</option><option value=\"Sweden\">Sweden</option>"
assert_dom_equal(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册