NoMethodError(类:模块的未定义方法`作用域'):

时间:2012-11-07 03:34:45

标签: ruby-on-rails has-many-through

我有一个看起来像这样的has_many和has_many:through关系...

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

我正在尝试访问用户“通过”来宾列表对象......

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

并抛出以下错误......

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

我一直在寻找解决方案,但没有任何效果。请帮忙!

1 个答案:

答案 0 :(得分:2)

模型Patron中的关联出现问题。 Singularize usersguestlists。请参阅更多here

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