Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The action 'facebook' could not be found - devise/omniauth

I'm trying to implement facebook authentication in my app following this guide

After authorizing on Facebook I get the following:

Unknown action

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

I've got the method implemented in app/controller/users/omniauth_callbacks_controller.rb as:

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

My route for the callback is:

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

Is there something I'm missing? How can I go about debugging this?

Thanks!

Update: Added output of rake routes (sorry for the length):

          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
like image 618
Alan H Avatar asked Dec 16 '22 14:12

Alan H


1 Answers

Worked out what I had set up incorrectly! I initially followed a tutorial for Devise and added this to my routes:

devise_for :users

Then I followed the omniauth tutorial and added the following for the callbacks:

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

Somehow these must have been conflicting as simply removing the first record points the callback in the correct direction (it must have been looking to the Devise class that I sub-classed Devise::OmniauthCallbacksController).

like image 98
Alan H Avatar answered Dec 30 '22 13:12

Alan H