我有以下代碼:爲什麼我會收到「未初始化的常量」錯誤?
class Zombie < ActiveRecord::Base
attr_accessible :name, :rotting, :age
has_many :assignments
has_many :roles, through: :assignments
end
class Role < ActiveRecord::Base
attr_accessible :title
has_many :assignments
has_many :zombies, through: :assignments
end
class Assignments < ActiveRecord::Base
attr_accessible :role_id, :zombie_id
belongs_to :zombie
belongs_to :role
end
在控制檯中,當我嘗試運行此代碼:
zombie = Zombie.first
role = Role.first
zombie.assignments.create(role: role)
我收到以下錯誤:
NameError: uninitialized constant Zombie::Assignment.
難道我在這裏犯了什麼錯誤?
該解決方案使其工作,但不解決問題。 Rails模型是單數的,考慮將'Assignments'改爲'Assignment' –