Skip to content
Browse files

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
  • Loading branch information...
1 parent b55f59e commit 9015ce4cc243d4022e294b9062afe53d46910b06 @dhh dhh committed
View
2 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]
View
2 actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -83,6 +83,7 @@ def options_for_select(container, selected = nil)
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 @@ def options_for_select(container, selected = nil)
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
View
11 actionpack/test/template/form_options_helper_test.rb
@@ -94,6 +94,17 @@ def test_array_options_for_select_with_selection_array
)
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=\"&lt;Kroner&gt;\">&lt;DKR&gt;</option>\n<option value=\"Dollar\">$</option>",

0 comments on commit 9015ce4

Please sign in to comment.
Something went wrong with that request. Please try again.