aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorVasiliy Ermolovich <younash@gmail.com>2013-04-11 14:15:33 +0300
committerVasiliy Ermolovich <younash@gmail.com>2013-04-11 14:15:33 +0300
commit0778290b57433da3bcd707fce222b8f646b7de4f (patch)
treebd3589ac814dd90a9d98b67eb74e138cc1898354 /actionpack
parent2a07db716957bf1638a84aa3c1f69d26efdbdb7d (diff)
downloadrails-0778290b57433da3bcd707fce222b8f646b7de4f.tar.gz
rails-0778290b57433da3bcd707fce222b8f646b7de4f.tar.bz2
rails-0778290b57433da3bcd707fce222b8f646b7de4f.zip
options_from_collection_for_select helper takes html attributes
as the last element of the array
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md5
-rw-r--r--actionpack/lib/action_view/helpers/form_options_helper.rb2
-rw-r--r--actionpack/test/template/form_options_helper_test.rb7
3 files changed, 13 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md
index 913edbd8df..9106ec6ef4 100644
--- a/actionpack/CHANGELOG.md
+++ b/actionpack/CHANGELOG.md
@@ -1,4 +1,9 @@
## 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 `[]`),
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb
index 7e65ebb4e4..719c9c09b5 100644
--- a/actionpack/lib/action_view/helpers/form_options_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -380,7 +380,7 @@ module ActionView
# 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 = {
diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb
index 94ae8549f7..1715902927 100644
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -100,6 +100,13 @@ class FormOptionsHelperTest < ActionView::TestCase
)
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(