Skip to content

Instantly share code, notes, and snippets.

@shuma
Created February 28, 2013 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuma/5057344 to your computer and use it in GitHub Desktop.
Save shuma/5057344 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_create do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.email = auth.info.email
user.image = auth.info.image
user.location = auth.info.location
user.gender = auth.extra.raw_info.gender
user.urls = auth["info"]["urls"]["Facebook"]
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
user.add_friends
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment