diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-02-01 17:43:44 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-02-02 14:31:53 -0200 |
commit | 9035324367526af0300477a58b6d3efc15d1a5a8 (patch) | |
tree | 5c573d72ad9ba54e25243c5a1cbf15481129c961 /actionpack/lib/action_view/helpers | |
parent | b1619560614a49956828ec75aebaa4ad8b212684 (diff) | |
download | rails-9035324367526af0300477a58b6d3efc15d1a5a8.tar.gz rails-9035324367526af0300477a58b6d3efc15d1a5a8.tar.bz2 rails-9035324367526af0300477a58b6d3efc15d1a5a8.zip |
Allow proc for value/text method in collection_select
And options_from_collection_for_select as well.
[Carlos Antonio da Silva + Rafael Mendonça França]
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_options_helper.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/collection_helpers.rb | 4 |
2 files changed, 6 insertions, 6 deletions
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index cf56bf3b9a..cb94c8ca8a 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -360,7 +360,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| - [element.send(text_method), element.send(value_method)] + [value_for_collection(element, text_method), value_for_collection(element, value_method)] end selected, disabled = extract_selected_and_disabled(selected) select_deselect = { @@ -622,7 +622,7 @@ module ActionView [selected, nil] else selected = Array.wrap(selected) - options = selected.extract_options!.symbolize_keys + options = selected.extract_options!.symbolize_keys selected_items = options.fetch(:selected, selected) [selected_items, options[:disabled]] end @@ -637,6 +637,10 @@ module ActionView selected end end + + def value_for_collection(item, value) + value.respond_to?(:call) ? value.call(item) : item.send(value) + end end class FormBuilder diff --git a/actionpack/lib/action_view/helpers/tags/collection_helpers.rb b/actionpack/lib/action_view/helpers/tags/collection_helpers.rb index 4fc2293a8d..c5fa7e1458 100644 --- a/actionpack/lib/action_view/helpers/tags/collection_helpers.rb +++ b/actionpack/lib/action_view/helpers/tags/collection_helpers.rb @@ -72,10 +72,6 @@ module ActionView yield value, text, default_html_options end.join.html_safe end - - def value_for_collection(item, value) #:nodoc: - value.respond_to?(:call) ? value.call(item) : item.send(value) - end end end end |