Skip to content

Instantly share code, notes, and snippets.

@joker1007
Created June 17, 2012 08:20
Show Gist options
  • Save joker1007/2943882 to your computer and use it in GitHub Desktop.
Save joker1007/2943882 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
attr_accessible :image, :name, :provider, :screen_name, :uid
def self.find_or_create_with_omniauth(auth)
user = User.find_by_provider_and_uid(auth["provider"], auth["uid"])
unless user
user = User.new
user[:provider] = auth["provider"]
user[:uid] = auth["uid"]
unless auth["info"].blank?
user[:name] = auth["info"]["name"]
user[:screen_name] = auth["info"]["nickname"]
user[:image] = auth["info"]["image"]
end
user.save
end
user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment