diff options
author | Subba Rao Pasupuleti <subbarao.pasupuleti@gmail.com> | 2010-08-14 10:55:51 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-08-15 16:46:32 -0300 |
commit | 54477c98482f37d547fa158155ae1624b1f7f7ac (patch) | |
tree | bdf8d48a84cd7ed6036cd5400cf12fb51a588f45 /actionpack/lib | |
parent | fd78bb727045547371179428886c9b262d66091d (diff) | |
download | rails-54477c98482f37d547fa158155ae1624b1f7f7ac.tar.gz rails-54477c98482f37d547fa158155ae1624b1f7f7ac.tar.bz2 rails-54477c98482f37d547fa158155ae1624b1f7f7ac.zip |
select tags coerce the :selected option, options to strings before comparison [#5056 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_options_helper.rb | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 71ee970bee..43cbba8a0a 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -298,17 +298,18 @@ module ActionView return container if String === container container = container.to_a if Hash === container - selected, disabled = extract_selected_and_disabled(selected) + selected, disabled = extract_selected_and_disabled(selected).map do | r | + Array.wrap(r).map(&:to_s) + end - options_for_select = container.map do |element| + container.map do |element| html_attributes = option_html_attributes(element) - text, value = option_text_and_value(element) + text, value = option_text_and_value(element).map(&:to_s) selected_attribute = ' selected="selected"' if option_value_selected?(value, selected) disabled_attribute = ' disabled="disabled"' if disabled && option_value_selected?(value, disabled) - %(<option value="#{html_escape(value.to_s)}"#{selected_attribute}#{disabled_attribute}#{html_attributes}>#{html_escape(text.to_s)}</option>) - end + %(<option value="#{html_escape(value)}"#{selected_attribute}#{disabled_attribute}#{html_attributes}>#{html_escape(text)}</option>) + end.join("\n").html_safe - options_for_select.join("\n").html_safe end # Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the @@ -528,10 +529,12 @@ module ActionView end def extract_selected_and_disabled(selected) - if selected.is_a?(Hash) - [selected[:selected], selected[:disabled]] + if selected.is_a?(Proc) + [ selected, nil ] else - [selected, nil] + selected = Array.wrap(selected) + options = selected.extract_options!.symbolize_keys + [ options[:selected] || selected , options[:disabled] ] end end |