<%= f.select(:company_id, Company.all.collect {|company| [company.name, company.id]}) %>
我如何从A-Z中对此进行排序?
答案 0 :(得分:4)
<%= f.select :company_id, Company.all.collect{|company| [company.name, company.id]}.sort_by{|a, b| a} %>
或者
<%= f.select :company_id, Company.all.collect{|company| [company.name, company.id]}.sort{|a, b| a[0] <=> b[0]} %>
<强> UPD 强>
或者只是<%= f.select :company_id, Company.all.map{ |c| [c.name, c.id] }.sort %>
- Phrogz