我看过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, broadcasts, :id, :to_s,
{:include_blank => 'Broadcast on...'}, {:class => 'prevent_collapse'}
你有什么错误?
广播项目是否有 :to_s
方法?正如我所想,它将返回类名。
关于ruby-on-rails - 将类添加到 collection_select,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4945081/