Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.