aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/form_options_helper.rb
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-05-19 09:49:01 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-05-19 09:58:14 -0300
commit0e207a499f82c7aefabcddad04fc562df727e663 (patch)
treefd86ff69d3bfe66f6f7168656347e51c0d8cb309 /actionpack/lib/action_view/helpers/form_options_helper.rb
parent3e7070622af7b6efe9eb86c2275b2ad895bd5510 (diff)
downloadrails-0e207a499f82c7aefabcddad04fc562df727e663.tar.gz
rails-0e207a499f82c7aefabcddad04fc562df727e663.tar.bz2
rails-0e207a499f82c7aefabcddad04fc562df727e663.zip
Clarify grouped_options_for_select method API, add changelog entry
Make the method API more clear by explicitly showing the expected arguments. This means that the options cannot be passed as second argument because we are not relying on extract_options! anymore, you are expected to give a selected key or `nil` if you want to pass options, as it is the last argument. Notice that this does not change the current method arguments contract available in 3.2, it just brings back the same functionality with the divider addition.
Diffstat (limited to 'actionpack/lib/action_view/helpers/form_options_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/form_options_helper.rb27
1 files changed, 13 insertions, 14 deletions
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb
index 52eb1aa447..eef426703d 100644
--- a/actionpack/lib/action_view/helpers/form_options_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -477,8 +477,8 @@ module ActionView
#
# Sample usage (Hash):
# grouped_options = {
- # 'North America' => [['United States','US'], 'Canada'],
- # 'Europe' => ['Denmark','Germany','France']
+ # 'North America' => [['United States','US'], 'Canada'],
+ # 'Europe' => ['Denmark','Germany','France']
# }
# grouped_options_for_select(grouped_options)
#
@@ -495,10 +495,10 @@ module ActionView
#
# Sample usage (divider):
# grouped_options = [
- # [['United States','US'], 'Canada'],
- # ['Denmark','Germany','France']
+ # [['United States','US'], 'Canada'],
+ # ['Denmark','Germany','France']
# ]
- # grouped_options_for_select(grouped_options, divider: '---------')
+ # grouped_options_for_select(grouped_options, nil, divider: '---------')
#
# Possible output:
# <optgroup label="---------">
@@ -513,15 +513,14 @@ module ActionView
#
# <b>Note:</b> Only the <tt><optgroup></tt> and <tt><option></tt> tags are returned, so you still have to
# wrap the output in an appropriate <tt><select></tt> tag.
- def grouped_options_for_select(*args)
- grouped_options = args.shift
- options = args.extract_options!
- selected_key = args.shift
- if prompt = args.shift
- ActiveSupport::Deprecation.warn 'Passing the prompt to grouped_options_for_select as an argument is deprecated. Please pass it in an options hash.'
- else
- prompt = options[:prompt]
+ def grouped_options_for_select(grouped_options, selected_key = nil, options = {})
+ if options.is_a?(Hash)
+ prompt = options[:prompt]
divider = options[:divider]
+ else
+ prompt = options
+ options = {}
+ ActiveSupport::Deprecation.warn "Passing the prompt to grouped_options_for_select as an argument is deprecated. Please use an options hash like `{ prompt: #{prompt.inspect} }`."
end
body = "".html_safe
@@ -534,7 +533,7 @@ module ActionView
grouped_options.each do |container|
if divider
- label, container = divider, container
+ label = divider
else
label, container = container
end