diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-01-31 18:58:31 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-02-02 09:40:24 -0200 |
commit | 4a18cbb6dd7ba9b6c5bd3e42b43fece6644735c2 (patch) | |
tree | 6ac8e4aab7317dd5191bc39707c285443c17630e /actionpack | |
parent | 595271cbd2a763103223026b893a4ca3c98978c7 (diff) | |
download | rails-4a18cbb6dd7ba9b6c5bd3e42b43fece6644735c2.tar.gz rails-4a18cbb6dd7ba9b6c5bd3e42b43fece6644735c2.tar.bz2 rails-4a18cbb6dd7ba9b6c5bd3e42b43fece6644735c2.zip |
Cleanup options helper methods a bit
[Carlos Antonio da Silva + Rafael Mendonça França]
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_options_helper.rb | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 75ffb0d282..6e0c0b6e2c 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -363,9 +363,10 @@ module ActionView [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 @@ module ActionView 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 @@ module ActionView 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 |