Integrating with acts_as_list

sj26 edited this page Aug 1, 2012 · 5 revisions

If you want acts_as_list to work with ancestry, getting the sorting "sorted out" can be tricky.

class Page < ActiveRecord::Base
  has_ancestry
  acts_as_list scope: [:ancestry]
end

The trick here is wrapping :ancestry in an Array. This causes acts_as_list to treat the scope as a hash condition (:ancestry => ancestry) which correctly becomes ancestry IS NULL or ancestry = 'some value' as necessary.