加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 将类添加到collection_select

发布时间:2020-12-16 22:11:41 所属栏目:百科 来源:网络整理
导读:我看过 How do I set the HTML options for collection_select in Rails?,我相信我错过了一些明显的东西,但是我不能让这个工作. 我的选择目前看起来像: %= f.collection_select :broadcast_id,broadcasts,:id,:to_s,:include_blank = 'Broadcast on...' %
我看过 How do I set the HTML options for collection_select in Rails?,我相信我错过了一些明显的东西,但是我不能让这个工作.

我的选择目前看起来像:

<%= f.collection_select :broadcast_id,broadcasts,:id,:to_s,:include_blank => 'Broadcast on...' %>

我尝试过包括:class => ‘prevent_collapse’,它什么都不做,以及{:class => ‘prevent_collapse’},这给我一个错误.

如果有人可以指出如何做到这一点,我将非常感激!

解决方法

collection_select(object,method,collection,value_method,text_method,options = {},html_options = {})
=>
f.collection_select :broadcast_id,{:include_blank => 'Broadcast on...'},{:class => 'prevent_collapse'}

你有什么错误?

广播项目有没有得到:to_s方法?就像我想的那样返回类名.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读