Now i'm using this code:
User has_one User_extra
User => :username, :email, :crypted_password, :salt, :mobile
User_extra => :user_id, :date_birth, :gender, :address
user.rb
class User < ActiveRecord::Base
authenticates_with_sorcery!
attr_accessible :username, :email, :password, :password_confirmation, :first_name,
:user_extra_attributes
has_one :user_extra, :dependent => :destroy
accepts_nested_attributes_for :user_extra
end
user_extra.rb
class UserExtra < ActiveRecord::Base
belongs_to :user
end
users_controller.rb
def new
@user = User.new
@user.build_user_extra
end
def edit
@user = User.find_by_permalink(params[:id])
@user.build_user_extra
end
If you worked with Sorcery gem, you'd probably know that any new attributes should be added to attr_accessible, so in my case it's: user_extra_attributes, but if I add it, then there appears error:
Can't mass-assign protected attributes: date_birth(1i), date_birth(2i), date_birth(3i),
gender, address
, so, then i added them one by one to attr_accessible like this:
attr_accessible :gender, :address ...
but it's anyway throwing an error:
Can't mass-assign protected attributes: date_birth(1i), date_birth(2i), date_birth(3i), gender, address
What could be the problem ??
You should add the attr_accessible :gender, :address, etc. to the UserExtra model