如何使用简单的表单对集合进行排序

Yan*_*all 2 collections ruby-on-rails-3 simple-form

我正在从模型中提取类别列表.在管理部分,我想用它来为产品分配类别.它工作正常,但列表按顺序显示已添加类别.我想按字母顺序对它们进行排序,但我无法将其排除在外.

我相信这很简单(希望如此)

这是我的代码:

<%= simple_form_for(@game) do |f| %>
  <%= f.input :name %>
  <%= f.input :description %>
  <%= f.input :copy %>
  <%= f.input :image %>
  <%= f.input :thumbnail %>
  <%= f.input :heroimage %>
  <%= f.association :category, collection: @categories %>
  <%= f.button :submit %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

我试图添加一个.sort_by(desc)或只是.sort在收集方法,但它不会更改列表.

干杯

小智 5

以下是更新代码的方法:

<%= f.association :category, collection: Category.order('name ASC') %>
Run Code Online (Sandbox Code Playgroud)

这假设您希望按类别名称按升序排序.