NoMethodError (undefined method `scoped' for Class:Module):-Collection of common programming errors

I have a has_many and has_many :through relationship that looks like this…

class Guestlist < ActiveRecord::Base
    belongs_to :venues

    has_many :patrons
    has_many :users, :through => :patrons

    attr_accessible :capacity, :end_time, :name, :start_time, :venue_id
end

class Patron < ActiveRecord::Base
    belongs_to :guestlists
    belongs_to :users
    attr_accessible :guestlist_id, :user_id, :checked_in
end

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  attr_accessible :name, :email, :password, :password_confirmation, :remember_me

  has_many :patrons
  has_many :guestlists, :through => :patrons
end

I am trying to access the users “through” guestlist object…

@guestlist = Guestlist.find(params[:id])
@guests = @guestlist.users.order('name ASC')

and the following error is thrown…

NoMethodError (undefined method `scoped' for Users:Module)

I’ve been searching all over for a solution but nothing works. Please help!

  1. Looks something wrong with your associations in Model Patron. Singularize users and guestlists. Refer more here

    class Patron < ActiveRecord::Base
        belongs_to :guestlist 
        belongs_to :user
        attr_accessible :guestlist_id, :user_id, :checked_in
    end
    

Originally posted 2013-11-10 00:16:55.