私は、電話番号をボランティア (および後で他のもの) にポリモーフィックに関連付ける作業を行っていますが、現在、次のエラーが発生しています。
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
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)
ここに任意の入力で新しいボランティアを作成しようとすると、エラーが発生します。現在のリクエストの例は次のとおりです。
{"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"=>"✓"}
注:アドレスクラスもありますが、すでに機能しているので、この投稿を混乱させませんでした。
フォーラムをブラウジングしたところ、他の人にとっての主な問題は多言語化だったように見えましたが、私が知る限り、すべて正しく多言語化されています。
また、phone_id または primaryPhone_id を人間のボランティア テーブルに追加しようとしましたが、役に立ちませんでした。
ありがとうございました - ケン