我希望-6ren">
gpt4 book ai didi

ruby-on-rails - 包括 collection_select 助手的空白和默认值

转载 作者:行者123 更新时间:2023-12-01 22:36:38 26 4
gpt4 key购买 nike

我希望在我的 Rails 应用程序的下拉菜单中有一个“选择一个选项”选项。

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

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

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

最佳答案

使用 include_blank 选项:

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

参见 official documentation here

关于ruby-on-rails - 包括 collection_select 助手的空白和默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22230261/

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