如何包含“请选择...” (默认/提示)在分组下拉列表中?
我用于下拉列表的代码是这样的:
<%= f.select :post_type_id, option_groups_from_collection_for_select(@categories, :post_types, :name, :id, :name) %>
它将选项整齐地划分为选项组。
但是如何修改代码以包含“请选择...”的提示(或默认值)?
分组下拉菜单似乎很难做到。 (rails 文档似乎建议使用哈希,但我尝试了几种替代方法但没有成功。)
The code I am using for the dropdown list is this:
<%= f.select :post_type_id, option_groups_from_collection_for_select(@categories, :post_types, :name, :id, :name) %>
It neatly divides the options into optgroups.
But how do I modify the code to include a prompt (or a default value) of "Please select..." ?
It seems hard to do with grouped dropdowns.
(The rails docs seem to suggest using a hash, but I've tried several alternatives without success.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊,在我发布问题后,我发现答案就在
select
的文档中,而不是在我一直在寻找的option_groups_from_collection_for_select
文档中。答案是:
Bah, right after I posted the question I found the answer was in the docs for
select
, and not underoption_groups_from_collection_for_select
docs where I had been looking.The answer is: