diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-16 16:15:50 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-16 16:15:50 -0700 |
commit | 66cbde016c5c457f25c45a71ef8839608ef77299 (patch) | |
tree | cb813763bdf421914aa2c4e9e9330002680c001d /actionpack/lib | |
parent | 8e5f07dabcb2d917105aa7ae678072ab44bd5ad4 (diff) | |
parent | a1ae17e32797c1e0607c08bbcce1f257eecedf7d (diff) | |
download | rails-66cbde016c5c457f25c45a71ef8839608ef77299.tar.gz rails-66cbde016c5c457f25c45a71ef8839608ef77299.tar.bz2 rails-66cbde016c5c457f25c45a71ef8839608ef77299.zip |
Merge pull request #5369 from Greenie0506/add_separator_to_grouped_options_for_select
Add separator option to grouped_options_for_select
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_options_helper.rb | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 7e33ca2fac..f39a1d95ea 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -492,13 +492,28 @@ 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(grouped_options, selected_key = nil, prompt = nil) + 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] + divider = options[:divider] + end + body = "".html_safe body.safe_concat content_tag(:option, prompt, :value => "") if prompt grouped_options = grouped_options.sort if grouped_options.is_a?(Hash) - grouped_options.each do |label, container| + grouped_options.each do |container| + if divider + label, container = divider, container + else + label, container = container + end body.safe_concat content_tag(:optgroup, options_for_select(container, selected_key), :label => label) end |