我有以下代码:
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.
我在这里犯了什么错误吗?