Ruby on rails Formtastic集合排序

Ruby on rails Formtastic集合排序,ruby-on-rails,ruby,ruby-on-rails-3,sql-order-by,formtastic,Ruby On Rails,Ruby,Ruby On Rails 3,Sql Order By,Formtastic,我需要为formtastic按州分类,无论它们是否被选中 我的设置与下面的类似 # user.rb class User has_and_belongs_to_many :colours end ` ` ordered\u for返回排序良好的数组。事实上,formtastic随后会破坏此顺序,并按id对颜色进行排序 有什么好的方法来抑制这种行为?有没有更聪明的方法通过选择实现订单 提前谢谢 请尝试: Colour.ordered_for(current_user).all # _for

我需要为formtastic按州分类,无论它们是否被选中

我的设置与下面的类似

# user.rb
class User
  has_and_belongs_to_many :colours
end
`

`

ordered\u for
返回排序良好的数组。事实上,formtastic随后会破坏此顺序,并按
id
对颜色进行排序

有什么好的方法来抑制这种行为?有没有更聪明的方法通过选择实现订单

提前谢谢

请尝试:

Colour.ordered_for(current_user).all
# _form.html.haml
= semantic_form_for(@user) do |f|
  = f.input :colours, :as => :check_boxes, :collection => Colour.ordered_for(current_user)
Colour.ordered_for(current_user).all