0
formtastic에 대한 컬렉션을 상태별로 정렬해야합니다. 선택되어 있는지 여부를 선택해야합니다.Formtastic Collection Sorting
내 설정은 다음과
# user.rb
class User
has_and_belongs_to_many :colours
end
'
# colour.rb
class Colour
has_and_belongs_to_many :users
scope :ordered_for, lambda { |user|
all.sort_by { |s| include? user ? 1 : 0 }
}
end
'
# _form.html.haml
= semantic_form_for(@user) do |f|
= f.input :colours, :as => :check_boxes, :collection => Colour.ordered_for(current_user)
ordered_for
가 잘 정렬 된 배열을 반환 비슷합니다. 실제로 formtastic은이 순서를 파괴하고 색을 id
으로 정렬합니다.
그 행동을 극복하는 좋은 접근 방법은 무엇입니까? 선택을 통해 주문을하는 더 똑똑한 방법이 있습니까?
미리 감사드립니다.
나는 OO을 무슨 그 – pex