Skip to content

Instantly share code, notes, and snippets.

@davidedicillo
Created January 19, 2014 19:34
Show Gist options
  • Select an option

  • Save davidedicillo/8509892 to your computer and use it in GitHub Desktop.

Select an option

Save davidedicillo/8509892 to your computer and use it in GitHub Desktop.
class Answer < ActiveRecord::Base
belongs_to :user
belongs_to :question
end
class Question < ActiveRecord::Base
belongs_to :user
has_many :answers, :dependent => :destroy
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
user = User.where(:provider => auth.provider, :uid => auth.uid).first
if user
return user
else
registered_user = User.where(:email => auth.info.email).first
if registered_user
return registered_user
else
user = User.create(name:auth.extra.raw_info.name,
provider:auth.provider,
uid:auth.uid,
email:auth.info.email,
password:Devise.friendly_token[0,20],
)
end
end
end
has_many :questions
has_many :answers
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment