Using devise as my authentication system I would like to build my profile on user registration.
I read many topics about this on SO, and decided to take the approach of building the profile within the model:
profile.rb
class Profile < ActiveRecord::Base
belongs_to :user
attr_accessible :user_id, # FIXME This is secure?
end
user.rb
class User < ActiveRecord::Base
devise ...
has_one :profile
accepts_nested_attributes_for :profile
def build_profile
Profile.create(:user_id => id)
end
end
My two questions are:
Is having the user_id in attr_accessible dangerous (mass-assignement)?
Did I have to put my profile creation in a controller (registration create) using a transaction? (Here if my profile fails to build I have still a user record)