Rails LinkedIn Ошибка входа
Я пытался понять, как решить эту проблему часами, и не могу. Я продолжаю получать эту ошибку:
Невозможно загрузить константу OmniauthCallbacksController, ожидается, что /Users/omar.amiri/Desktop/rails-devise-roles/app/controllers/omniauth_callbacks_controller.rb определит ее
omniauth_callbacks_controller.rb
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def linkedin
auth = env["omniauth.auth"]
@user = User.connect_to_linkedin(request.env["omniauth.auth"],current_user)
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.linkedin_uid"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end
user.rb.rb
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.connect_to_linkedin(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.info.first_name,
provider:auth.provider,
uid:auth.uid,
email:auth.info.email,
password:Devise.friendly_token[0,20],
)
end
end
end
end
routes.rb
Rails.application.routes.draw do
root to: 'visitors#index'
devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }
resources :users
end