Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Excise ingrown code from FormOptionsHelper#options_for_select. Closes #…

…5008.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4331 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 5a960d2568b5c2f69c31379045a224489a5ac3d1 1 parent d249ff5
@jeremy jeremy authored
View
2  actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Excise ingrown code from FormOptionsHelper#options_for_select. #5008 [anonymous]
+
* Small fix in routing to allow dynamic routes (broken after [4242]) [Rick]
map.connect '*path', :controller => 'files', :action => 'show'
View
2  actionpack/lib/action_view/helpers/form_options_helper.rb
@@ -113,7 +113,6 @@ def options_for_select(container, selected = nil)
options_for_select = container.inject([]) do |options, element|
if !element.is_a?(String) and element.respond_to?(:first) and 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>"
@@ -121,7 +120,6 @@ def options_for_select(container, selected = nil)
options << "<option value=\"#{html_escape(element.last.to_s)}\">#{html_escape(element.first.to_s)}</option>"
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 value=\"#{html_escape(element.to_s)}\" selected=\"selected\">#{html_escape(element.to_s)}</option>" : "<option value=\"#{html_escape(element.to_s)}\">#{html_escape(element.to_s)}</option>")
end
View
4 actionpack/test/template/form_options_helper_test.rb
@@ -103,6 +103,10 @@ def test_array_options_for_string_include_in_other_string_bug_fix
"<option value=\"ruby\" selected=\"selected\">ruby</option>\n<option value=\"rubyonrails\">rubyonrails</option>",
options_for_select([ "ruby", "rubyonrails" ], "ruby")
)
+ assert_dom_equal(
+ %(<option value="ruby" selected="selected">ruby</option>\n<option value="rubyonrails">rubyonrails</option>\n<option value=""></option>),
+ options_for_select([ "ruby", "rubyonrails", nil ], "ruby")
+ )
end
def test_hash_options_for_select
Please sign in to comment.
Something went wrong with that request. Please try again.