gpt4 book ai didi

ruby-on-rails - 使用 SimpleForm 为每个选择选项添加一个类

转载 作者:行者123 更新时间:2023-12-04 05:57:46 25 4
gpt4 key购买 nike

我想建一个select来自数组(而不是模型集合)的输入,使用 SimpleForm,并且每个 option 都有不同的类s。

我希望这会奏效:

f.input :method, collection: [
["option text", "option_value_1", { class: "class_name_1" }],
["option text 2", "option_value_2", { class: "class_name_2" }]
]

问题是它会产生:
<select>
<option value="option text" class="class_name_1">option text</option>
<option value="option text 2" class="class_name_2">option text 2</option>
</select>

我怎样才能用简单的形式做我想做的事(值应该是“选项值”)?

最佳答案

这似乎是使用集合时的限制,请参阅 SimpleForm 解释的作者 here .他建议采用以下形式的解决方法:

f.input :method, :as => :select do
f.select :method, [['option text', 'option_value_1', {"class" => "class_name_1"}], ['option text 2', 'option_value_2', {"class" => "class_name_2"}]]
end

关于ruby-on-rails - 使用 SimpleForm 为每个选择选项添加一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15190988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com