如何在rails中的collection方法中使用order

时间:2013-09-25 09:37:02

标签: ruby-on-rails

这是我的代码,我无法通过first_name

对名称进行排序
 <%= f.collection_select :donation_id, @donation_array,
      :id,  :dropdown_display,:order => ("first_name DESC"),
      :prompt => "Select Donation Detail", :include_blank => true %>

1 个答案:

答案 0 :(得分:0)

你不能这样订购,当你像这样拉动donation_array时就完成了

@donation_array = Donation.order('first_name DESC').all

并像这样创建你的收藏

<%= f.collection_select :donation_id, @donation_array,
      :id,  :dropdown_display,
      :prompt => "Select Donation Detail", :include_blank => true %>