无法找到'facebook'动作 - devise / omniauth

时间:2013-02-02 03:59:05

标签: ruby-on-rails ruby-on-rails-3 devise omniauth

我正在尝试在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

1 个答案:

答案 0 :(得分:12)

解决了我错误设置的问题!我最初遵循了Devise的教程并将其添加到我的路线中:

devise_for :users

然后我按照omniauth教程并为回调添加了以下内容:

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

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