Ruby on rails 创建提要=>;NoMethodError:ActiveRecord\u关联\u CollectionProxy的未定义方法

Ruby on rails 创建提要=>;NoMethodError:ActiveRecord\u关联\u CollectionProxy的未定义方法,ruby-on-rails,rails-activerecord,has-many-through,model-associations,rails-postgresql,Ruby On Rails,Rails Activerecord,Has Many Through,Model Associations,Rails Postgresql,我正在实现一个属于用户订阅的标签的所有卡片的提要,我得到以下错误。这可能是一些琐碎的事情,但我无法确定哪些工作需要改进 NoMethodError:undefined方法“cards”标记::ActiveRecord\u Associations\u CollectionProxy:0x007fbaa46239f8> 以下是我的模型: class User < ActiveRecord::Base has_many :cards, dependent: :destroy has_m

我正在实现一个属于用户订阅的标签的所有卡片的提要,我得到以下错误。这可能是一些琐碎的事情,但我无法确定哪些工作需要改进

NoMethodError:undefined方法“cards”标记::ActiveRecord\u Associations\u CollectionProxy:0x007fbaa46239f8>

以下是我的模型:

class User < ActiveRecord::Base
  has_many :cards, dependent: :destroy
  has_many :tags, through: :cards

  has_many :subscriptions, dependent: :destroy 
  has_many :subscribed_tags, through: :subscriptions, source: :tag
end
class Tag < ActiveRecord::Base
  has_many :taggings, dependent: :destroy
  has_many :cards, through: :taggings
  has_many :subscriptions, dependent: :destroy
  has_many :subscribers, through: :subscriptions, source: :user
end
class Card < ActiveRecord::Base
  acts_as_votable
  belongs_to :user
  has_many :taggings, dependent: :destroy
  has_many :tags, through: :taggings    
  def self.tagged_with(name)
    Tag.find_by_name!(name).cards
  end
  def self.tag_counts
    Tag.select("tags.*, count(taggings.tag_id) as count").
    joins(:taggings).group("taggings.tag_id")
  end
  def tag_list
     tags.map(&:name).join(", ")
  end
  def tag_list=(names)
    self.tags = names.split(",").map do |n|
       Tag.where(name: n.strip).first_or_create!
    end
  end
end
class用户
我真正想做的是运行current_user.subscribed_tags.cards并检索一组可以重新排序并作为时间线输出的卡片


感谢
subscribed\u tags
-这是一个作用域(
where(user:self)
),您可以调用
where
join
,但不是一个项方法

在您的情况下,您希望使用
范围

class Card
  scope :with_subscription, -> { joins(tags: :subscriptions) }
end

# In controller
current_user.cards.with_subscription.order('cards.created_at DESC')
你可以想象
current\u user.cards
就像另一种形式的
cards.where(user:current\u user)
。一旦您告知您将检索
阵列-它无法更改。您不能执行
user.cards.subscriptions
user.where(id:user.cards.tags
唯一可以执行此操作的筛选器

接下来,我们使用
联接(:订阅)
进行过滤。它将给我们内部连接,所以我们得到属于有订阅的用户的卡。这是一个范围,我们可以进一步修改传递,例如订单


您想检索当前用户的标签数组或当前用户的已订阅标签的卡片数组?woops,typo:当前用户的子立方体标签的卡片数组我得到了一个未定义的方法,该方法与卡片类的订阅有关,当我考虑额外的“s”时,我仍然会得到错误。。。有什么想法吗?在阅读了指南之后,我真的要返回当前用户已订阅的标签中的所有卡片吗?我忘记了冒号。重试。仍然会出现错误“意外的“{”,应为关键字\u end scope:with\u subscription{joins(:subscriptions)}”我正在使用rails 4.2.1,如果这有什么帮助的话,我真的不应该在这些事情上依赖内存。再试一次。最终我们会解决这个问题。哈哈,不用担心,谢谢。我收到了一个activerecord::configurationerror。并且在卡上找不到名为“订阅”的关联;也许是您拼写错误了?