gpt4 book ai didi

css - 以 Rails 4 形式向 grouped_options_for_select 添加类

转载 作者:行者123 更新时间:2023-11-28 11:32:52 25 4
gpt4 key购买 nike

我似乎无法让这个 select 上的类起作用。分组集合有效......但不是类:

 = f.select :topic_id, grouped_options_for_select([['News',  @topics.news.order(title: :asc).collect {|v| [ v.title, v.id ] }],
['Opinion', @topics.opinion.order(title: :asc).collect {|v| [ v.title, v.id ] }]]), html: {include_blank: false , id: 'page_topic', class: 'form-control'}

最佳答案

尝试不使用 html: 键:

= f.select :topic_id, grouped_options_for_select([['News',  @topics.news.order(title: :asc).collect {|v| [ v.title, v.id ] }],
['Opinion', @topics.opinion.order(title: :asc).collect {|v| [ v.title, v.id ] }]]), include_blank: false, id: 'page_topic', class: 'form-control'

附言您的代码很难阅读,请尝试将一些部分提取到变量中,如下所示:

- news_options = ['News', @topics.news.order(title: :asc).collect {|v| [ v.title, v.id ] } ]
- opinion_options = ['Opinion', @topics.opinion.order(title: :asc).collect {|v| [ v.title, v.id ] }]
- options = grouped_options_for_select([news_options, opinion_options])
= f.select :topic_id, options, include_blank: false, id: 'page_topic', class: 'form-control'

关于css - 以 Rails 4 形式向 grouped_options_for_select 添加类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33001495/

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