Ben*_*Ben 29 forms ruby-on-rails ruby-on-rails-3 simple-form
我在我的应用程序中使用simple_form.
如何在我选择空白值时选择不同于""的文本?
我只是找到一个包含空白的选项.
Jos*_*ore 53
本,
这取决于您如何构建选择选项.如果你像下面的代码那样做,只需将一个字符串传递给:include空白.
select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {:include_blank => 'Some text here'})
Run Code Online (Sandbox Code Playgroud)
如果您使用options_for_select()设置选项,则可以执行以下操作:
options_for_select([["Dollar", "$"], ["Kroner", "DKK"]])
Run Code Online (Sandbox Code Playgroud)
使用value =""作为数组中的第二个值,并且首先显示在下拉列表中的名称.因此,在您的情况下,您可以将第二个答案更改为如下所示:
options_for_select([["Some text here", ""], ["Dollar", "$"], ["Kroner", "DKK"]])
Run Code Online (Sandbox Code Playgroud)
Dem*_*nou 33
代替
:include_blank => true
Run Code Online (Sandbox Code Playgroud)
尝试
:include_blank => "your text here"
Run Code Online (Sandbox Code Playgroud)
如果这是你正在寻找的.
Geo*_*rgi 22
如果您正在使用该select_tag(name, option_tags = nil, options = {})函数,则正确的选项:prompt => "Some text"不是为其设置字符串值select
| 归档时间: |
|
| 查看次数: |
26998 次 |
| 最近记录: |