Skip to content

Commit 474ff55

Browse files
committed
[actionview] [Fix rails#54966] Check choice type before calling .second to detect grouped_choices in Select helper
1 parent 0ed3cd4 commit 474ff55

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

actionview/lib/action_view/helpers/tags/select.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ def render
3737
# [nil, []]
3838
# { nil => [] }
3939
def grouped_choices?
40-
!@choices.blank? && @choices.first.respond_to?(:second) && Array === @choices.first.second
40+
return false if @choices.blank?
41+
42+
first_choice = @choices.first
43+
return false unless first_choice.is_a?(Enumerable)
44+
45+
first_choice.second.is_a?(Array)
4146
end
4247
end
4348
end

actionview/test/template/form_options_helper_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,13 @@ def test_select
537537
)
538538
end
539539

540+
def test_select_with_class
541+
assert_dom_equal(
542+
"<select name=\"post[class]\" id=\"post_class\"><option value=\"Struct::Post\">Struct::Post</option></select>",
543+
select(:post, :class, [Post])
544+
)
545+
end
546+
540547
def test_select_without_multiple
541548
assert_dom_equal(
542549
"<select id=\"post_category\" name=\"post[category]\"></select>",

0 commit comments

Comments
 (0)