trying to get users to login using facebook but i get
routing error: uninitialized constant Users::OmiauthCallbackController error
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@user = User.find_or_create_from_auth_hash auth_hash
if @user.persisted?
sign_in_and_redirect @user
else
session["devise.user_attributes"] = @user.attributes
redirect_to new_user_registration_url, notice: "Oops, something went wrong"
end
end
private
def auth_hash request.env['omniauth.auth'] end end
routes file
Fbapp::Application.routes.draw do devise_for :users, controllers: {omniauth_callbacks: 'users/omiauth_callback'} resources :posts
get "pages/home" root "pages#home"
user rb file
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_or_create_from_auth_hash(auth_hash)
find_by_auth_hash(auth_hash) || create_from_auth_hash(auth_hash)
end
def self.find_by_auth_hash(auth_hash)
where(
provider: auth_hash.provider,
uid: auth_hash.uid
).first
end
def self.create_from_auth_hash(auth_hash)
create(
provider: auth_hash.provider,
uid: auth_hash.uid,
email: auth_hash.info.email,
name: auth_hash.info.name,
oauth_token: auth_hash.credentials.token,
oauth_expires_at: Time.at(auth_hash.credentials.expires_at)
)
end
def password_required?
super && provider.blank?
end
def update_with_password(params, *options)
if encrypted_password.blank?
update_attributes(params, *options)
else
super
end
end
end
def facebook
@facebook ||= Koala::Facebook::API.new(oauth_token)
end
def get_profile_info
self.facebook.get_object("me")
end
def get_location
h = get_profile_info["location"]
h["name"]
end
def get_books
self.facebook.get_connection("me", "books")
end
def get_profile_picture
self.facebook.get_picture(uid)
end
end