我正在尝试使用Devise with Omniauth选项创建Rails应用程序以进行用户管理。我试图让一个OAuth服务一次工作,从Github开始。欢迎页面加载,我点击使用Github登录,转到Github授权页面并允许,然后重定向开始,我收到错误消息The action 'github' could not be found for Devise::OmniauthCallbacksController
。
我不明白为什么我会收到此错误b / c我已在app / controllers / users / omniauth_callbacks_controller.rb中定义了该操作,如下所示:
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def github
@user = User.from_omniauth(request.env["omniauth.auth"])
sign_in_and_redirect @user
end
end
应用程序/模型/ 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
Rails.application.routes.draw do
get 'welcome/index'
root 'welcome#index'
devise_for :users, :controller => { :omniauth => "users/omniauth_callbacks" }
end
它试图回退到默认的Devise OmniauthsCallbacksController而不是使用我的用户/ omniauths_callbacks_controller.rb,但我不知道为什么。有什么建议吗?
可能相关的信息:
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
答案 0 :(得分:1)
尝试替换
function Welcome($content) {
$welcome = '';
if ( is_page('Profile'))
$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$numb = str_replace('mysite.org/profile/?user_id=', '', $url);
global $wpdb;
$query = $wpdb->prepare ('SELECT `membership_level_id` FROM `mm_user_data` WHERE `wp_user_id` = %d', $numb);
$idnum= $wpdb->get_var($query);
$query = $wpdb->prepare ('SELECT `name` FROM `mm_membership_levels` WHERE `id` = %d', $idnum);
$text= $wpdb->get_var($query);
$text="<h3>$text</h3>";
return $text.$content;
}
add_filter('the_content', 'Welcome');
到
devise_for :users, :controller => { :omniauth => "users/omniauth_callbacks" }