2011-10-12 40 views
2

如何按名称排序?f.collection_select按名称排列

<%= f.collection_select :carmodel_id_equals, Carmodel.all, :id, :name, :include_blank => true %> 

我在这里找过一些搜索结果,但没有任何工作。 p.s.这是一个meta_search f.select表单。谢谢。

+1

尝试'<%= f.collection_select:carmodel_id_equals,Carmodel.order('name ASC')。all,:id,:name,:include_blank => true%>' – sled

+0

把它作为答案,所以我可以给你一些观点:)。它正在工作。 – rmagnum2002

回答

10

你就必须使用order这样的命令从Carmodel.all搜索结果:Carmodel.order('name ASC').all

所以,如果你把它放在一起,应该是这样的:

<%= f.collection_select :carmodel_id_equals, Carmodel.order('name ASC').all, :id, :name, :include_blank => true %>

阅读更真棒Rails Guide