How can I delegate to scope ? rails

Viewed 2985

I have :

class UserItem < ActiveRecord::Base

  belongs_to :user
  belongs_to :item

  scope :equipped, -> { where(equipped: true) }
end

class Item < ActiveRecord::Base
   has_many :user_items
   has_many :users, through: :user_items

   scope :armor, -> { where(type: 'Armor') }
   delegate :equipped, to: :user_items

end

EDIT:

If i try

User.first.items.equipped => undefined method 'equipped' for #<ActiveRecord::Associations::CollectionProxy []>

User.first.items.armor.equipped => undefined method 'equipped' for #<ActiveRecord::AssociationRelation []>

How can I delegate to scope?

1 Answers
Related