【问题标题】:rails 4: Adding a class to a select tagrails 4:将类添加到选择标签
【发布时间】:2016-10-04 17:50:43
【问题描述】:

尝试将类添加到选择标签

<%= f.select(:ptype, options_for_select(TourParticipation::PTYPES, selected: "traveler", disabled: "Role:") , { :class => "widens" } ) %>

结果

<select name="tour_participation[ptype]" id="tour_participation_ptype"></select>

为什么类没有应用于我的选择标签?

【问题讨论】:

    标签: ruby ruby-on-rails-4 formbuilder actionview


    【解决方案1】:

    您忘记了html_options 之前是options 哈希。试试这个:

    <%= f.select(:ptype, options_for_select(TourParticipation::PTYPES, selected: "traveler", disabled: "Role:") , {}, { :class => "widens" } ) %>
    

    见定义: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select

    【讨论】:

    • 正确的语法是:&lt;%= f.select(:ptype, options_for_select(TourParticipation::PTYPES, selected: "traveler", disabled: "Role:"), {}, class: "widens") %&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 2019-06-10
    • 2019-01-07
    • 2016-10-01
    • 2022-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多