包括空白和collection_select helper的默认值 [英] Include blank and default for collection_select helper

查看:61
本文介绍了包括空白和collection_select helper的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to have a "select an option" option in my dropdown on my rails application.

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

I am using the collection_select helper tag and it looks something like this:

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

我希望下拉菜单的默认选项为选择国家/地区".

I want the default option of the drop-down to be "Select a country".

推荐答案

使用 include_blank 选项:

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

请参见此处的官方文档

这篇关于包括空白和collection_select helper的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆