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

时间:2011-01-08 03:48:44

标签: ruby-on-rails ruby-on-rails-3

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

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

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

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

由于

1 个答案:

答案 0 :(得分:21)

只需在:include_blank => 'All People'中添加select_tag选项:

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