我有以下内容创建一个选择框:
<%=select_tag "people", options_from_collection_for_select(@people, "id", "name")%>
这会为每个人创建一个项目,问题是我想要一个“所有人”值0,默认情况下在加载时添加和选择选项?
rails 3中的select_tag是否支持此功能?
由于
答案 0 :(得分:21)
只需在:include_blank => 'All People'
中添加select_tag
选项:
<%= select_tag "people", options_from_collection_for_select(@people, "id", "name"), :include_blank => 'All People' %>