我正在编写像这样选择的选项。它没有给出任何错误,但类属性不会出现在生成的html中。
<%= f.select(:late_penalty, options_for_select([["Days in Week", "Days in Week"],
["Days in Month", "Days in Month"]], :selected => @late_early.late_penalty) , { :class => 'my_style_class' })%>
答案 0 :(得分:4)
试试这个会起作用
<%= f.select(:late_penalty,
options_for_select([
["Days in Week", "Days in Week"],
["Days in Month", "Days in Month"]],
:selected => @late_early.late_penalty),
{ } , { :class => 'my_style_class' })%>
答案 1 :(得分:1)
问题是必须将HTML属性作为第四个参数传递给select
,但是您将它们作为第三个参数提供。 (第三个参数适用于:include_blank
等选项。)这是你想要的:
<%= f.select(:late_penalty,
options_for_select(
[ [ "Days in Week", "Days in Week" ],
[ "Days in Month", "Days in Month" ]
],
:selected => @late_early.late_penalty
),
nil,
{ :class => 'my_style_class' }
)
%>