User.init method inside User.rb. Is this good practice?

I’m sort of conflicted here. I’m using CanCan and it automatically load
and
authorize User/Create.

My Facebook/Init is as follows. I’m tempted to do something similar and
call User/Init from User/Create method. This way I hide the
implementation
in the UserController so User/Create and User/Update will still call the
User/Init method. The problem starts when I need the Controller to know
whether it is a new record or just an update.

Would you do this differently?

class Facebook < ActiveRecord::Base

belongs_to :user

def self.init(fb_user)

user = User.find_by_identifier(fb_user.try(:identifier).try(:to_s))

if user

  user.identifier   = fb_user.try(:identifier).try(:to_s)

  user.access_token = fb_user.access_token.try(:to_s)

else

  user = User.new

  user.updating_password = true

  user.identifier   = fb_user.try(:identifier).try(:to_s)

  user.access_token = fb_user.try(:access_token).try(:to_s)

  user.username     = fb_user.try(:username).try(:to_s)


  user.send_registration_confirmation

end

user

end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs