gpt4 book ai didi

ruby-on-rails - 无法找到操作 'facebook' - devise/omniauth

转载 作者:行者123 更新时间:2023-12-04 03:53:30 26 4
gpt4 key购买 nike

我正在尝试在 this guide 之后在我的应用程序中实现 Facebook 身份验证

在 Facebook 上授权后,我得到以下信息:

Unknown action

The action 'facebook' could not be found for Devise::OmniauthCallbacksController

我在 app/controller/users/omniauth_callbacks_controller.rb 中实现了该方法:
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
# You need to implement the method below in your model (e.g. app/models/user.rb)
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user)

if @user.persisted?
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_user_registration_url
end
end
end

我的回调路线是:
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

有什么我想念的吗?我该如何去调试这个?

谢谢!

更新:添加了 rake 路由的输出(抱歉长度):
          new_user_session GET    /users/sign_in(.:format)                   devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_omniauth_authorize /users/auth/:provider(.:format) devise/omniauth_callbacks#passthru {:provider=>/facebook/}
user_omniauth_callback /users/auth/:action/callback(.:format) devise/omniauth_callbacks#(?-mix:facebook)
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
help /help(.:format) static_pages#help
about /about(.:format) static_pages#about
contact /contact(.:format) static_pages#contact
users_new GET /users/new(.:format) users#new
signup /signup(.:format) users#new
new_certificate /new_certificate(.:format) users#newcertificate
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_omniauth_authorize /users/auth/:provider(.:format) users/omniauth_callbacks#passthru {:provider=>/facebook/}
user_omniauth_callback /users/auth/:action/callback(.:format) users/omniauth_callbacks#(?-mix:facebook)
POST /users/password(.:format) devise/passwords#create
GET /users/password/new(.:format) devise/passwords#new
GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
GET /users/cancel(.:format) devise/registrations#cancel
POST /users(.:format) devise/registrations#create
GET /users/sign_up(.:format) devise/registrations#new
GET /users/edit(.:format) devise/registrations#edit
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
GET /users/auth/:provider(.:format) users/omniauth_callbacks#passthru
courses GET /courses(.:format) courses#index
POST /courses(.:format) courses#create
new_course GET /courses/new(.:format) courses#new
edit_course GET /courses/:id/edit(.:format) courses#edit
course GET /courses/:id(.:format) courses#show
PUT /courses/:id(.:format) courses#update
DELETE /courses/:id(.:format) courses#destroy
enrollments GET /enrollments(.:format) enrollments#index
POST /enrollments(.:format) enrollments#create
new_enrollment GET /enrollments/new(.:format) enrollments#new
edit_enrollment GET /enrollments/:id/edit(.:format) enrollments#edit
enrollment GET /enrollments/:id(.:format) enrollments#show
PUT /enrollments/:id(.:format) enrollments#update
DELETE /enrollments/:id(.:format) enrollments#destroy
submissions GET /submissions(.:format) submissions#index
POST /submissions(.:format) submissions#create
new_submission GET /submissions/new(.:format) submissions#new
edit_submission GET /submissions/:id/edit(.:format) submissions#edit
submission GET /submissions/:id(.:format) submissions#show
PUT /submissions/:id(.:format) submissions#update
DELETE /submissions/:id(.:format) submissions#destroy
honour_code_signatures GET /honour_code_signatures(.:format) honour_code_signatures#index
POST /honour_code_signatures(.:format) honour_code_signatures#create
new_honour_code_signature GET /honour_code_signatures/new(.:format) honour_code_signatures#new
edit_honour_code_signature GET /honour_code_signatures/:id/edit(.:format) honour_code_signatures#edit
honour_code_signature GET /honour_code_signatures/:id(.:format) honour_code_signatures#show
PUT /honour_code_signatures/:id(.:format) honour_code_signatures#update
DELETE /honour_code_signatures/:id(.:format) honour_code_signatures#destroy
root / static_pages#home

最佳答案

解决了我设置不正确的问题!我最初遵循了 Devise 的教程并将其添加到我的 route :

devise_for :users

然后我遵循了 omniauth 教程并为回调添加了以下内容:
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

不知何故,这些肯定是有冲突的,因为简单地删除第一个记录将回调指向正确的方向(它一定是在寻找我将 Devise::OmniauthCallbacksController 子类化的 Devise 类)。

关于ruby-on-rails - 无法找到操作 'facebook' - devise/omniauth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14658439/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com