Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AbstractExternalUser < ActiveRecord::Base
- after_create :create_associated_user_profile
- has_one :profile, :class_name => 'User'
- validates_associated :profile
- attr_accessor :no_callbacks
- def self.create_without_profile(attributes={})
- user = self.new(attributes)
- user.no_callbacks = true
- user.save
- end
- protected
- # callback to set custom user attributes
- # override in child class
- def custom_attributes
- end
- def create_associated_user_profile
- if self.profile.nil? && !self.no_callbacks
- self.custom_attributes
- default_info = {
- :login => self.login,
- :email => self.email,
- :password => self.password,
- :password_confirmation => self.password
- }
- self.create_profile( default_info )
- end
- end
- end
Add Comment
Please, Sign In to add comment