From 9015ce4cc243d4022e294b9062afe53d46910b06 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 15 Mar 2005 00:13:14 +0000 Subject: Fixed options_for_select on selected line issue #624 [Florian Weber] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@911 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_view/helpers/form_options_helper.rb | 2 ++ actionpack/test/template/form_options_helper_test.rb | 11 +++++++++++ 3 files changed, 15 insertions(+) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 3470e0ae14..9488d7847d 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed options_for_select on selected line issue #624 [Florian Weber] + * Added CaptureHelper with CaptureHelper#capture and CaptureHelper#content_for. See documentation in helper #837 [Tobias Luetke] * Fixed :anchor use in url_for #821 [Nicholas Seckar] diff --git a/actionpack/lib/action_view/helpers/form_options_helper.rb b/actionpack/lib/action_view/helpers/form_options_helper.rb index 99114b8694..fd8a347cb0 100644 --- a/actionpack/lib/action_view/helpers/form_options_helper.rb +++ b/actionpack/lib/action_view/helpers/form_options_helper.rb @@ -83,6 +83,7 @@ module ActionView options_for_select = container.inject([]) do |options, element| if element.respond_to?(:first) && element.respond_to?(:last) is_selected = ( (selected.respond_to?(:include?) ? selected.include?(element.last) : element.last == selected) ) + is_selected = ( (selected.respond_to?(:include?) && !selected.is_a?(String) ? selected.include?(element.last) : element.last == selected) ) if is_selected options << "" else @@ -90,6 +91,7 @@ module ActionView end else is_selected = ( (selected.respond_to?(:include?) ? selected.include?(element) : element == selected) ) + is_selected = ( (selected.respond_to?(:include?) && !selected.is_a?(String) ? selected.include?(element) : element == selected) ) options << ((is_selected) ? "" : "") end end diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb index a94f81a728..962d0c5069 100644 --- a/actionpack/test/template/form_options_helper_test.rb +++ b/actionpack/test/template/form_options_helper_test.rb @@ -94,6 +94,17 @@ class FormOptionsHelperTest < Test::Unit::TestCase ) end + def test_array_options_for_string_include_in_other_string_bug_fix + assert_equal( + "\n", + options_for_select([ "ruby", "rubyonrails" ], "rubyonrails") + ) + assert_equal( + "\n", + options_for_select([ "ruby", "rubyonrails" ], "ruby") + ) + end + def test_hash_options_for_select assert_equal( "\n", -- cgit v1.2.3