假设我们有一个具有树状结构 (acts_as_tree) 的 List
模型。因此,每个列表都可以有父项和/或子项。
基本上,我希望列表的每个子项都在其父项范围内定义position
字段,如何实现?
class List < ActiveRecord::Base
acts_as_tree
# acts_as_list scope: :parent <-- desired result
end
或者,换句话说,acts_as_list怎么能在 List
模型中使用 gem?
最佳答案
似乎将 acts_as_list
的范围限定到非关联的 :parent_id
字段(这是 acts_as_tree
gem 工作所必需的)完成了这项工作:
class List < ActiveRecord::Base
acts_as_tree
acts_as_list scope: [:parent_id]
end
关于ruby-on-rails - acts_as_list inside acts_as_tree,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32949178/