带中间表的act_as_list

时间:2016-05-27 15:08:29

标签: ruby-on-rails ruby-on-rails-4

我试图使用act_as_list来订购一些商品,但是我的范围有问题,我希望范围是商品的组,但我不知道怎么做。这就是我现在所拥有的:

class Group < ActiveRecord::Base
  has_many :types
  has_many :items, through: :types
end

class Type < ActiveRecord::Base
  belongs_to :group
  has_many :items
end

class Item < ActiveRecord::Base
  belongs_to :type
  acts_as_list scope: ?
end

我尝试了范围:[type :: group]但它没有用,我试过:

has_one :group, through: :type

def group_id
  type.group.id
end

但后来我的PG出错,因为列group_id不存在......

有什么想法吗?

0 个答案:

没有答案
相关问题