對於我的數據模型,我有兩種不同的類型:家庭成員和朋友。我的計劃是讓每個都有一個由Devise創建的用戶表的外鍵。所以,當用戶註冊時,我希望他們去/ friends/sign_up或family_members/sign_up。所以,我的朋友類是設計的未知屬性
class Friend < ActiveRecord::Base
belongs_to :label
belongs_to :user
belongs_to :gender
belongs_to :location
belongs_to :orientation
belongs_to :matchmaker
def after_initialize
self.build_user if self.user.nil?
end
#accepts_nested_attributes_for :user
delegate :username, :to => :user
delegate :email, :to => :user
delegate :password, :to => :user
delegate :password_confirmation, :to => :user
delegate :rememebr_me, :to => :user
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
end
和我的User類是
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
# devise :database_authenticatable, :registerable,
# :recoverable, :rememberable, :trackable, :validatable
attr_accessor :username, :email, :password, :password_confirmation, :remember_me
# Setup accessible (or protected) attributes for your model
attr_accessible :username, :email, :password, :password_confirmation, :remember_me
end
我還使用Formtastic對我的看法。 現在,我越來越
unknown attribute: username
與參數
{"utf8"=>"✓", "authenticity_token"=>"8ScsJebuCWnflaRQkp9MsBuaaqfzQKaZBXotLyNwNyM=",
"friend"=>{"username"=>"aaaa",
"email"=>"[email protected]",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]"},
"commit"=>"Create Friend"}
現在,我只是隨意嘗試添加nested_attributes和任何兩個型號。我可以使用表Inhertence,但我不希望(除非我可以添加一個外鍵指向超類的子類,那很好)。
我實際上在我的代碼中,它只是做了一個壞的複製粘貼作業。 – me2