Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 作为带有中间表的列表_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 作为带有中间表的列表

Ruby on rails 作为带有中间表的列表,ruby-on-rails,ruby-on-rails-4,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 &

我试图使用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

但是我在PG中遇到了一个错误,因为列组id不存在

有什么想法吗

has_one :group, through: :type
def group_id
  type.group.id
end