在多个列上使用acts_as_list

Mat*_*dan 6 ruby-on-rails acts-as-list

我有一个可能独特的情况,我需要一个模型,根据它加入的模型有两个不同的顺序.示例如下:

class Book
  acts_as_list :column => :genre, :scope => :genre
  acts_as_list :column => :author, :scope => :author
  belongs_to :genre
  belongs_to :author
end
Run Code Online (Sandbox Code Playgroud)

所以基本上我要做的是有一个Book模型,它是两个列表的一部分,一个用于它出现的类型页面,另一个用于它出现的作者页面.

acts_as_list似乎不支持使用2 move_to_top位列作为方法,例如不允许您指定要移动到顶部的列表.

有没有人对我如何实现这一点有任何建议?现在我想我将不得不创建一个连接表,例如books_genres有一个position列,但我真的不太热衷于此,因为这需要一大堆额外的表.

小智 1

充当不是为多列设计的列表。如果您想以这种方式使用它,插件几乎将重写。但我认为你可以尝试这样做。

class Book
  belongs_to :genre
  belongs_to :author
end

class GenreBook < Book
  acts_as_list :column => :genre, :scope => :genre
end

class AuthorBook < Book
  acts_as_list :column => :author, :scope => :author
end
Run Code Online (Sandbox Code Playgroud)

不确定它是否有效。理论上是可能的。