diff options
author | Greenie0506 <greenie0506@gmail.com> | 2012-05-15 13:45:12 -0400 |
---|---|---|
committer | Greenie0506 <greenie0506@gmail.com> | 2012-05-15 13:45:12 -0400 |
commit | a1ae17e32797c1e0607c08bbcce1f257eecedf7d (patch) | |
tree | 4f10cd87c99af05d5f0cba67b876905c317bb40d /actionpack/lib | |
parent | 9b4f5041d29f7e558f3286d40e5dc9edbe96cfb6 (diff) | |
download | rails-a1ae17e32797c1e0607c08bbcce1f257eecedf7d.tar.gz rails-a1ae17e32797c1e0607c08bbcce1f257eecedf7d.tar.bz2 rails-a1ae17e32797c1e0607c08bbcce1f257eecedf7d.zip |
Add separator argument to grouped_options_for_select
Change prompt to options hash in 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 |