Ken*_*och 0 polymorphism ruby-on-rails uninitialized-constant
我正在努力将电话号码与志愿者(以及后来的其他事情)进行多态关联,目前我遇到了以下错误:
uninitialized constant HumanVolunteer::PrimaryPhone
app/controllers/human_volunteers_controller.rb:44:in `new'
app/controllers/human_volunteers_controller.rb:44:in `create'
Run Code Online (Sandbox Code Playgroud)
这是我的PhoneNumbers模型:
class PhoneNumber < ActiveRecord::Base
attr_accessible :notes, :number
belongs_to :phone, :polymorphic => true
end
Run Code Online (Sandbox Code Playgroud)
这是我的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
Run Code Online (Sandbox Code Playgroud)
我的电话号码和人工志愿者的架构:
表: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)
Run Code Online (Sandbox Code Playgroud)
表:phone_numbers
id integer
number character varying(255)
notes text
created_at timestamp without time zone
updated_at timestamp without time zone
phone_id integer
phone_type character varying(255)
Run Code Online (Sandbox Code Playgroud)
当我尝试在任何输入下创建新的志愿者时,错误发生在这里是我当前的示例请求:
{"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"=>"?"}
Run Code Online (Sandbox Code Playgroud)
注意:我也有一个地址类,但我已经有了这个工作,所以我没有弄乱这篇文章.
从在浏览器上浏览看起来似乎其他人的主要问题是可塑性,但据我所知,我已经完全正确地解决了所有问题.
我还尝试将phone_id或primaryPhone_id添加到人类志愿者表中,但它没有帮助.
非常感谢, - 肯
| 归档时间: |
|
| 查看次数: |
3261 次 |
| 最近记录: |