Skip to content

Commit

Permalink
refactor grouped_options_for_select
Browse files Browse the repository at this point in the history
  • Loading branch information
nashby committed Feb 20, 2012
1 parent eff507f commit 421025f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions actionpack/lib/action_view/helpers/form_options_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -472,16 +472,16 @@ def option_groups_from_collection_for_select(collection, group_method, group_lab
# <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)
body = ''
body << content_tag(:option, prompt, { :value => "" }, true) if prompt
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 |group|
body << content_tag(:optgroup, options_for_select(group[1], selected_key), :label => group[0])
grouped_options.each do |label, container|
body.safe_concat content_tag(:optgroup, options_for_select(container, selected_key), :label => label)
end

body.html_safe
body
end

# Returns a string of option tags for pretty much any time zone in the
Expand Down

0 comments on commit 421025f

Please sign in to comment.