我正在努力将电话号码与志愿者(以及后来的其他事情)进行多态关联,目前我遇到了以下错误:
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) …Run Code Online (Sandbox Code Playgroud)