【问题标题】:Include blank and default for collection_select helper为 collection_select 助手包括空白和默认值
【发布时间】:2014-03-06 16:28:53
【问题描述】:

我想在我的 rails 应用程序的下拉菜单中添加一个“选择一个选项”选项。

我正在使用collection_select 辅助标签,它看起来像这样:

<%= collection_select(:country, :id, Country.order('name ASC'), :id,:name, {},{:class => "input-xlarge"}) %>

我希望下拉菜单的默认选项是“选择国家”。

【问题讨论】:

    标签: ruby-on-rails helper


    【解决方案1】:

    使用include_blank 选项:

    <%= collection_select(:country, :id, Country.order('name ASC'),
          :id, :name, 
          { include_blank: 'Select a country' }, 
          { :class => "input-xlarge" }) %>
    

    official documentation here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-17
      相关资源
      最近更新 更多