Ruby on rails 如何获得模型的汇总列表';领域?

Ruby on rails 如何获得模型的汇总列表';领域?,ruby-on-rails,arrays,model,relation,Ruby On Rails,Arrays,Model,Relation,我用的是ROR5。我有这个型号 class Article < ApplicationRecord ... has_and_belongs_to_many :contributors, :optional => false 类文章false 那么假设我有一系列的文章模型。如何获得贡献者的完整列表?我试过这个 articles.each do |article| @contributors << article.contributors end @con

我用的是ROR5。我有这个型号

class Article < ApplicationRecord
    ...
  has_and_belongs_to_many :contributors, :optional => false
类文章false
那么假设我有一系列的文章模型。如何获得贡献者的完整列表?我试过这个

articles.each do |article|
  @contributors << article.contributors
end
@contributors
articles.each do| article|
@贡献者尝试:

有关详细信息,您可以在中签出

当然,这是假设

class Contributor < ApplicationRecord
  has_and_belongs_to_many :articles
end
……自:

article.contributors

…返回一个
ActiveRecord\u Associations\u CollectionProxy
。当然,
ActiveRecord\u Associations\u CollectionProxy
,正如错误所说,没有方法
id

你有一个
文章的
数组
?或者,您有一些其他类型的ActiveRecord
可枚举
,比如
关系
?您是否在您的
Contributor
模型中调用了
has\u和\u belown\u\u许多:文章
?这有帮助吗?你最后做了什么?
class Contributor < ApplicationRecord
  has_and_belongs_to_many :articles
end
undefined method `id' for #<Contributor::ActiveRecord_Associations_CollectionProxy:0x00007f828a834028>
articles.each do |article|
  @contributors << article.contributors
end
@contributors
article.contributors