rails选择表格标签 - 如何添加默认的“全部”选项?

时间:2022-12-10 19:42:02

I have the following which creates a select box:

我有以下创建一个选择框:

<%=select_tag "people", options_from_collection_for_select(@people, "id", "name")%>

This creates an item for each person, problem is I would like a "All People" value 0, option added and selected by default on load?

这会为每个人创建一个项目,问题是我想要一个“所有人”值0,默认情况下在加载时添加和选择选项?

does the select_tag in rails 3 support this?

rails 3中的select_tag是否支持此功能?

Thanks

谢谢

1 个解决方案

#1


21  

Simply include a :include_blank => 'All People' option in your select_tag:

只需在select_tag中包含:include_blank =>'所有人'选项:

<%= select_tag "people", options_from_collection_for_select(@people, "id", "name"), :include_blank => 'All People' %>

#1


21  

Simply include a :include_blank => 'All People' option in your select_tag:

只需在select_tag中包含:include_blank =>'所有人'选项:

<%= select_tag "people", options_from_collection_for_select(@people, "id", "name"), :include_blank => 'All People' %>