For my data model, I have two different types: family members and friends. My plan is to have each have a foreign key to a User table, which is created by Devise. So, when a user signs up, I want them to either go to /friends/sign_up or family_members/sign_up . So, my 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 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
and my User class is
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
I'm also using Formtastic for my 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 just randomly trying to add nested_attributes and whatever to the two models. I could use table inhertence, but I'd prefer not to (unless I can add a foreign key to the subclassses pointing at the superclass, that would be fine).