diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-15 00:13:14 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-15 00:13:14 +0000 |
commit | 9015ce4cc243d4022e294b9062afe53d46910b06 (patch) | |
tree | c07463574516a89cfd10214681871d0f7983c705 | |
parent | b55f59e811564604a86dcaba23e3d27c32812f17 (diff) | |
download | rails-9015ce4cc243d4022e294b9062afe53d46910b06.tar.gz rails-9015ce4cc243d4022e294b9062afe53d46910b06.tar.bz2 rails-9015ce4cc243d4022e294b9062afe53d46910b06.zip |
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
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_options_helper.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_options_helper_test.rb | 11 |
3 files changed, 15 insertions, 0 deletions
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 << "<option value=\"#{html_escape(element.last.to_s)}\" selected=\"selected\">#{html_escape(element.first.to_s)}</option>" 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) ? "<option selected=\"selected\">#{html_escape(element.to_s)}</option>" : "<option>#{html_escape(element.to_s)}</option>") 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( + "<option>ruby</option>\n<option selected=\"selected\">rubyonrails</option>", + options_for_select([ "ruby", "rubyonrails" ], "rubyonrails") + ) + assert_equal( + "<option selected=\"selected\">ruby</option>\n<option>rubyonrails</option>", + options_for_select([ "ruby", "rubyonrails" ], "ruby") + ) + end + def test_hash_options_for_select assert_equal( "<option value=\"<Kroner>\"><DKR></option>\n<option value=\"Dollar\">$</option>", |