Skip to content

Instantly share code, notes, and snippets.

@madhums
Created November 16, 2010 12:31
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 madhums/701756 to your computer and use it in GitHub Desktop.
Save madhums/701756 to your computer and use it in GitHub Desktop.
authorization model
#/app/models/authorization.rb
class Authorization < ActiveRecord::Base
belongs_to :user
validates_presence_of :user_id, :uid, :provider
validates_uniqueness_of :uid, :scope => :provider
def self.find_from_hash(hash)
find_by_provider_and_uid(hash['provider'], hash['uid'])
end
def self.create_from_hash(hash, user = nil)
user ||= User.create_from_hash(hash)
Authorization.create(:user_id => user.id, :uid => hash['uid'], :provider => hash['provider'])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment