Skip to content

Instantly share code, notes, and snippets.

@assimovt
Created November 21, 2010 10:07
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 assimovt/708617 to your computer and use it in GitHub Desktop.
Save assimovt/708617 to your computer and use it in GitHub Desktop.
Railscast #236 extension with Fb_graph
# app/models/user.rb
def apply_omniauth(omniauth)
case omniauth['provider']
when 'facebook'
self.apply_facebook(omniauth)
end
authentications.build(:provider => omniauth['provider'], :uid => omniauth['uid'], :token =>(omniauth['credentials']['token'] rescue nil))
end
def facebook
@fb_user ||= FbGraph::User.me(self.authentications.find_by_provider('facebook').token)
end
protected
def apply_facebook(omniauth)
if (extra = omniauth['extra']['user_hash'] rescue false)
self.email = (extra['email'] rescue '')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment