2014-04-13 48 views
-1

我試圖找到外科醫生和約會之間的關係。鋼軌Unizillaize常數在協會

2.0.0-p195 :001 > surgeon = Surgeon.first 
    Surgeon Load (0.1ms) SELECT "surgeons".* FROM "surgeons" ORDER BY "surgeons"."id" ASC LIMIT 1 
=> #<Surgeon id: 5, name: "Micheal Gorbachev", created_at: "2014-04-13 07:15:42", updated_at: "2014-04-13 07:15:42"> 

2.0.0-p195 :008 > surgeon.appointments 
NameError: uninitialized constant Surgeon::Appointment 

但這個工程

2.0.0-P195:007> surgeon.association:約會

2.0.0-p195 :007 > surgeon.association :appointments 
    => #<ActiveRecord::Associations::HasManyAssociation:0x00000002a46850 
    @reflection=#<ActiveRecord::Reflection::AssociationReflection:0x000000030dc4d0 
    @macro=:has_many, @name=:appointments, @scope=nil, @options={}, 
    @active_record=Surgeon(id: integer, name: string, created_at: datetime, 
    updated_at: datetime), @plural_name="appointments", @collection=true>, 
    @owner=#<Surgeon id: 5, name: "Micheal Gorbachev", created_at: "2014-0 

enter image description here

這是我的模型

class Surgeon < ActiveRecord::Base 
     has_and_belongs_to_many :instruments 

     #section 2 
     has_many :appointments 
     has_many :interventions, :through => :appointments 
    end 
    class Intervention < ActiveRecord::Base 
     has_and_belongs_to_many :instruments 

     #section 2 
     has_many :appointments 
     has_many :surgeons, :through => :appointments 
    end 
    class Instrument < ActiveRecord::Base 
     has_and_belongs_to_many :surgeons 
     has_and_belongs_to_many :interventions 
    end 
    class Appointments < ActiveRecord::Base 

     #section 2 
     belongs_to :surgeon 
     belongs_to :intervention 
    end 

回答

0

楷模 必須用單數來命名,而不是複數。

class Appointment < ActiveRecord::Base 
+0

謝謝!我已經做了更正。比我重新加載!我的控制檯。但我仍然有'NameError:未初始化的常量醫生:: Appointment' –

+0

'2.0.0-P195:006> surgeon.methods.grep /委/ => [:autosave_associated_records_for_appointments,:validate_associated_records_for_appointments,:before_add_for_appointments,:before_add_for_appointments? :before_add_for_appointments =,:after_add_for_appointments,:after_add_for_appointments?,:after_add_for_appointments =,:before_remove_for_appointments,:before_remove_for_appointments?,:before_remove_for_appointments =,:after_remove_for_appointments,:after_remove_for_appointments ?,:after_remove_for_appointments =,:約會,:appointment_ids,:約會=,:appointment_ids = ] ' –

+0

'2.0.0-p195:007> surgeon.appointment_ids NameError:未初始化常量外科醫生::約會# –