diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb
index 4dafc471f8..6fc582ff65 100644
--- a/actionpack/lib/action_view/helpers/form_options_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -112,17 +112,9 @@ module ActionView
container = container.to_a if Hash === container
options_for_select = container.inject([]) do |options, element|
- if !element.is_a?(String) and element.respond_to?(:first) and element.respond_to?(:last)
- is_selected = ( (selected.respond_to?(:include?) && !selected.is_a?(String) ? selected.include?(element.last) : element.last == selected) )
- if is_selected
- options << ""
- else
- options << ""
- end
- else
- is_selected = ( (selected.respond_to?(:include?) && !selected.is_a?(String) ? selected.include?(element) : element == selected) )
- options << ((is_selected) ? "" : "")
- end
+ text, value = option_text_and_value(element)
+ selected_attribute = ' selected="selected"' if option_value_selected?(value, selected)
+ options << %()
end
options_for_select.join("\n")
@@ -130,18 +122,18 @@ module ActionView
# Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the
# the result of a call to the +value_method+ as the option value and the +text_method+ as the option text.
- # If +selected_value+ is specified, the element returning a match on +value_method+ will get the selected option tag.
+ # If +selected+ is specified, the element returning a match on +value_method+ will get the selected option tag.
#
# Example (call, result). Imagine a loop iterating over each +person+ in @project.people to generate an input tag:
# options_from_collection_for_select(@project.people, "id", "name")
#
#
# NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
- def options_from_collection_for_select(collection, value_method, text_method, selected_value = nil)
- options_for_select(
- collection.inject([]) { |options, object| options << [ object.send(text_method), object.send(value_method) ] },
- selected_value
- )
+ def options_from_collection_for_select(collection, value_method, text_method, selected = nil)
+ options = collection.map do |element|
+ [element.send(text_method), element.send(value_method)]
+ end
+ options_for_select(options, selected)
end
# Returns a string of option tags, like options_from_collection_for_select, but surrounds them with