2012-07-27 56 views
0

我正在做一個電話號碼的多態協會志願者工作(後來到了其他東西),目前我堅持以下錯誤:Rails的多態關聯未初始化的常量

uninitialized constant HumanVolunteer::PrimaryPhone 
app/controllers/human_volunteers_controller.rb:44:in `new' 
app/controllers/human_volunteers_controller.rb:44:in `create' 

這裏我PHONENUMBERS型號:

class PhoneNumber < ActiveRecord::Base 
    attr_accessible :notes, :number 

    belongs_to :phone, :polymorphic => true 
end 

這裏是我的HumanVolunteers型號:

class HumanVolunteer < ActiveRecord::Base 

    attr_accessible :firstName, :lastName, :homeaddressid, :notes, :status, :workdaddressid, :home_adr, :work_adr, :primaryPhone 
    has_one :primaryPhone, :as => :phone 

    def home_adr=(home_adr_arg) 
    # Home ADR 
    home_adr = Address.new(home_adr_arg) 
    if home_adr.save 
     self.homeaddressid = home_adr.id 
    end 
    end 

    def work_adr=(work_adr_arg) 
    # Work ADR 
    work_adr = Address.new(work_adr_arg) 
    if home_adr.save 
     self.workaddressid = work_adr.id 
    end 
    end 
end 

我的電話號碼和human_volunteers模式:

表:human_volunteers

id integer 
status character varying(255) 
homeaddressid integer  
workdaddressid integer  
notes text   
created_at timestamp without time zone 
updated_at timestamp without time zone 
firstName character varying(255)  
lastName character varying(255) 

表:PHONE_NUMBERS

​​

當我嘗試在任何輸入來創建一個新的志願者在這裏的錯誤是發生是我當前的示例請求:

{"human_volunteer"=>{"primaryPhone"=>"5555555555", 
"firstName"=>"", 
"notes"=>"", 
"work_adr"=>{"city"=>"", 
"state"=>"", 
"zipcode"=>"", 
"line1"=>"", 
"line2"=>""}, 
"home_adr"=>{"city"=>"", 
"state"=>"", 
"zipcode"=>"", 
"line1"=>"", 
"line2"=>""}, 
"lastName"=>""}, 
"authenticity_token"=>"RCPTxZpzytYXcDEUo0czRxpI4A3Qw1ErwcIBJ92RhLA=", 
"utf8"=>"✓"} 

注意:ia也有一個地址類,但我已經得到了這個工作,所以我沒有把它與這個帖子混爲一談。

從論壇上瀏覽看起來似乎是其他人的主要問題是塑化,但據我所知,我已經正確地塑造了一切。

我也嘗試添加一個phone_id或primaryPhone_id到人類志願者表,但它沒有幫助。

非常感謝你, - 肯

回答

8

has_one需要知道哪些類的指的。

 
    has_one :primary_phone, :class_name => "PhoneNumber", :as => :phone 
+0

謝謝,你能告訴我哪裏有記錄,我看了整個軌道的東西,並沒有看到任何關於它。我看到它的唯一地方是在「2.10自我加入」下。也還沒有更正,因爲現在我越來越 'PhoneNumber(#70073652768560)預計,得到的字符串(#70073736791040)' – 2012-07-27 21:01:46

+0

好吧,我想我看到發生了什麼,現在無關的問題。 我會繼續關注它,感謝您的幫助。 – 2012-07-27 21:29:13

相關問題