扶手:在活动记录未初始化的固定误差破坏 [英] Rails : uninitialized constant error on Active Record destroy
问题描述
我有试图摧毁一个活跃的记录实例时的问题。
I am having an issue when trying to destroy an active record instance.
这涉及到以下AR
class Client < ActiveRecord::Base
has_many :phone_numbers, :dependent => :destroy
has_many :email_addresses, :dependent => :destroy
has_many :user_clients , :dependent => :destroy
has_many :users, :through => :user_clients
end
class UserClient < ActiveRecord::Base
belongs_to :user
belongs_to :client , :dependent => :destroy
has_many :instructions, :dependent => :destroy
end
当执行摧毁一个Client实例,我给下面的错误
When performing a destroy on a Client instance I am given the following error
@dead_man = Client.find(params[:id])
@dead_man.destroy => uninitialized constant UserClient::Instruction
我真的不知道在这个错误的来源。任何帮助是极大AP preciated!
I am really not sure where this error is coming from. Any help is greatly appreciated!
推荐答案
这不是找你的教学模式。请确保它在车型目录,适当命名,延长的ActiveRecord :: Base的
等。
It's not finding your Instruction model. Make sure it's in the models directory, appropriately named, extends ActiveRecord::Base
, etc.
此外,你应该删除:依赖=&GT; :从
行,除非你真的想删除的user_client的导致删除客户端。这听起来像它应该是周围的其他方式,而这已经设立在客户端模式。 belongs_to的破坏
:在UserClient模型客户
Also, you should remove the :dependent => :destroy
from the belongs_to :client
line in the UserClient model, unless you really want deletion of a user_client to result in deletion of the client. It sounds like it should be the other way around, and that's already set up in the Client model.
这篇关于扶手:在活动记录未初始化的固定误差破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!