stevensonmt
stevensonmt

Reputation: 732

Devise OmniauthsController not being used

I am trying to create a Rails app using Devise with Omniauth options for user management. I am trying to get one OAuth service working at a time, starting with Github. The welcome page loads, I click sign in with Github, go to the Github authorization page and allow, then the redirect starts and I get the error message The action 'github' could not be found for Devise::OmniauthCallbacksController.

I do not understand why I'm getting this error b/c I have defined the action in app/controllers/users/omniauth_callbacks_controller.rb as follows:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def github
    @user = User.from_omniauth(request.env["omniauth.auth"])
    sign_in_and_redirect @user
  end

end

app/models/user.rb

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,     :omniauthable, :confirmable, :lockable, :omniauth_providers => [:github]

end

and app/config/routes.rb

Rails.application.routes.draw do
  get 'welcome/index'
  root 'welcome#index'

  devise_for :users, :controller => { :omniauth => "users/omniauth_callbacks" }
end

It's trying to fallback to the default Devise OmniauthsCallbacksController instead of using my users/omniauths_callbacks_controller.rb, but I don't know why. Any suggestions?

Possibly relevant info:

ruby v 2.4.0
rails v 50.0.1
omniauth v 1.3.2
devise v 4.2.0
omniauth-github v 1.1.2

Upvotes: 1

Views: 166

Answers (1)

VAD
VAD

Reputation: 2401

Try to replace

devise_for :users, :controller => { :omniauth => "users/omniauth_callbacks" }

to

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

Upvotes: 1

Related Questions