deviseを使用していて、ポリモーフィックな関係を作成したいので、テーブルユーザーの「usersable_type」と「usersable_id」に列を追加しました。
これは私のコードです
モデル>>ユーザー
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
# attr_accessible :title, :body
attr_accessible :email, :password, :password_confirmation, :remember_me
#usarsable
belongs_to :usersable, :polymorphic => true, :autosave => true, :dependent => :destroy
accepts_nested_attributes_for :usersable
end
モデル>>メディック
class Medic < ActiveRecord::Base
attr_accessible :license_number, :specialty
has_one :user, as: :usersable, dependent: :destroy
has_and_belongs_to_many :patients
end
モデル>>患者
class Patient < ActiveRecord::Base
belongs_to :socialsecurity
attr_accessible :birthday, :blood_type
has_one :user, as: :usersable, dependent: :destroy
has_many :contacts
has_and_belongs_to_many :medics
end
Deviseコントローラーをオーバーライドする
class RegistrationsController < Devise::RegistrationsController
def new
super
@user.build_usersable # I had problem in this line
end
def create
end
def update
super
end
end
これらはすべて私が今持っているモデルですが、それでも同じ問題があります。ポリモーフィックオブジェクトを作成して保存する方法がわかりません。
エラーはまだ同じです
エラー:「<#User:」の未定義のメソッド `build_usersable'
誰かが私を助けることができますか私は感謝します
よろしくお願いいたします。
ジュリ。