代码之家  ›  专栏  ›  技术社区  ›  stellard

Rails:活动记录销毁时出现未初始化常量错误

  •  13
  • stellard  · 技术社区  · 17 年前

    尝试销毁活动记录实例时遇到问题。

    它涉及以下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
    

    @dead_man = Client.find(params[:id])
    @dead_man.destroy => uninitialized constant UserClient::Instruction
    

    我真的不知道这个错误是从哪里来的。非常感谢任何帮助!

    2 回复  |  直到 17 年前
        1
  •  20
  •   Sarah Mei    17 年前

    ActiveRecord::Base

    :dependent => :destroy belongs_to :client

        2
  •  4
  •   Maragues    13 年前

    还要检查文件名是否与类名对应。就我而言,我有

    Class NameSpace::MyStats
    

    namespace/old_stats.rb
    

    namespace/my_stats.rb