Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleanup options helper methods a bit

[Carlos Antonio da Silva + Rafael Mendonça França]
  • Loading branch information...
commit 4a18cbb6dd7ba9b6c5bd3e42b43fece6644735c2 1 parent 595271c
@carlosantoniodasilva carlosantoniodasilva authored
Showing with 12 additions and 12 deletions.
  1. +12 −12 actionpack/lib/action_view/helpers/form_options_helper.rb
View
24 actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -363,9 +363,10 @@ def options_from_collection_for_select(collection, value_method, text_method, se
[element.send(text_method), element.send(value_method)]
end
selected, disabled = extract_selected_and_disabled(selected)
- select_deselect = {}
- select_deselect[:selected] = extract_values_from_collection(collection, value_method, selected)
- select_deselect[:disabled] = extract_values_from_collection(collection, value_method, disabled)
+ select_deselect = {
+ :selected => extract_values_from_collection(collection, value_method, selected),
+ :disabled => extract_values_from_collection(collection, value_method, disabled)
+ }
options_for_select(options, select_deselect)
end
@@ -522,11 +523,10 @@ def time_zone_options_for_select(selected = nil, priority_zones = nil, model = :
private
def option_html_attributes(element)
return "" unless Array === element
- html_attributes = []
- element.select { |e| Hash === e }.reduce({}, :merge).each do |k, v|
- html_attributes << " #{k}=\"#{ERB::Util.html_escape(v.to_s)}\""
- end
- html_attributes.join
+
+ element.select { |e| Hash === e }.reduce({}, :merge).map do |k, v|
+ " #{k}=\"#{ERB::Util.html_escape(v.to_s)}\""
+ end.join
end
def option_text_and_value(option)
@@ -552,12 +552,12 @@ def option_value_selected?(value, selected)
def extract_selected_and_disabled(selected)
if selected.is_a?(Proc)
- [ selected, nil ]
+ [selected, nil]
else
selected = Array.wrap(selected)
- options = selected.extract_options!.symbolize_keys
- selected_items = options.include?(:selected) ? options[:selected] : selected
- [ selected_items, options[:disabled] ]
+ options = selected.extract_options!.symbolize_keys
+ selected_items = options.fetch(:selected, selected)
+ [selected_items, options[:disabled]]
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.