未使用Devise OmniauthsController [英] Devise OmniauthsController not being used

查看:86
本文介绍了未使用Devise OmniauthsController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用具有Omniauth选项的Devise创建用于用户管理的Rails应用程序.我正试图从Github开始一次运行一项OAuth服务.欢迎页面加载,我单击使用Github登录,进入Github授权页面并允许,然后重定向开始,并显示错误消息The action 'github' could not be found for Devise::OmniauthCallbacksController.

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.

我不明白为什么会收到此错误b/c,我在app/controllers/users/omniauth_callbacks_controller.rb中定义了操作,如下所示:

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

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

和app/config/routes.rb

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

它试图回退到默认的Devise OmniauthsCallbacksController而不是使用我的users/omniauths_callbacks_controller.rb,但是我不知道为什么.有什么建议吗?

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?

可能相关的信息:

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

推荐答案

尝试替换

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

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

这篇关于未使用Devise OmniauthsController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆