在 haml 中使用 select

Using select in haml

我目前有这个 select 区块

= f.label :item
= f.select(:item, ["Select"] + List.items(foo), {}, { :class => "form-control input", :id => "column" })

我需要的是将默认选项设置为我想要的任何字符串,但我似乎不知道该把它放在哪里。

您不能使用 APIdock 中的 include_blank 选项吗?

= f.label :item
= f.select(:item, List.items(foo), {include_blank: 'String'}, {html_options})

http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/select

使用include_blank: 选项设置默认提示。例如:

= f.select(:title, Book.all, include_blank: "Anything!")

将呈现默认值为 "Anything" 的 select 标签。所以对于你的情况,我相信它会是:

= f.select(:item, ["Select"] + List.items(foo), {}, { :class => "form-control input", :id => "column", include_blank: 'Any string' })