ruby on rails - unknown attribute with devise -
for data model, have 2 different types: family members , friends. plan have each have foreign key user table, created devise. so, when user signs up, want them either go /friends/sign_up or family_members/sign_up . so, friend class is
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 , :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # setup accessible (or protected) attributes model attr_accessible :username, :email, :password, :password_confirmation, :remember_me end
and user class is
class user < activerecord::base # include default devise modules. others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable , :omniauthable # devise :database_authenticatable, :registerable, # :recoverable, :rememberable, :trackable, :validatable attr_accessor :username, :email, :password, :password_confirmation, :remember_me # setup accessible (or protected) attributes model attr_accessible :username, :email, :password, :password_confirmation, :remember_me end
i'm using formtastic view. right now, i'm getting
unknown attribute: username
with parameters
{"utf8"=>"✓", "authenticity_token"=>"8scsjebucwnflarqkp9msbuaaqfzqkazbxotlynwnym=", "friend"=>{"username"=>"aaaa", "email"=>"aaa@aaa.com", "password"=>"[filtered]", "password_confirmation"=>"[filtered]"}, "commit"=>"create friend"}
right now, i'm randomly trying add nested_attributes , whatever 2 models. use table inhertence, i'd prefer not (unless can add foreign key subclassses pointing @ superclass, fine).
ok, i've fixed problem satisfaction. here new code future reference:
class friend < activerecord::base belongs_to :friend_user, :class_name => end class frienduser < user set_table_name :users has_one :friend end class user < activerecord::base # include default devise modules. others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable , :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # setup accessible (or protected) attributes model attr_accessible :username, :email, :password, :password_confirmation, :remember_me end
Comments
Post a Comment