Guest User

Untitled

a guest
Mar 9th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. class AbstractExternalUser < ActiveRecord::Base
  2. after_create :create_associated_user_profile
  3. has_one :profile, :class_name => 'User'
  4. validates_associated :profile
  5.  
  6. attr_accessor :no_callbacks
  7.  
  8. def self.create_without_profile(attributes={})
  9. user = self.new(attributes)
  10. user.no_callbacks = true
  11. user.save
  12. end
  13.  
  14. protected
  15.  
  16. # callback to set custom user attributes
  17. # override in child class
  18. def custom_attributes
  19. end
  20.  
  21. def create_associated_user_profile
  22. if self.profile.nil? && !self.no_callbacks
  23. self.custom_attributes
  24. default_info = {
  25. :login => self.login,
  26. :email => self.email,
  27. :password => self.password,
  28. :password_confirmation => self.password
  29. }
  30. self.create_profile( default_info )
  31. end
  32. end
  33. end
Add Comment
Please, Sign In to add comment