Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

I've followed all the steps but get the following error after hitting login.

Unknown action

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

I've created the file omniauth_callbacks_controller in controllers/users. It has a facebook method defined. Any idea how I should debug?


Adding my routes file -

Myapp::Application.routes.draw do
  get "static_pages/home"

  get "static_pages/help"

  get "static_pages/about"

  devise_for :users do
    resources :posts

  end

  root :to => 'static_pages#home'

  devise_for :users, controllers: {omniauth_callbacks: "omniauth_callbacks"}
end
like image 273
Finnnn Avatar asked Jul 14 '12 11:07

Finnnn


2 Answers

If you look at the guide it specifies this line for your routes file:

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

where you have:

devise_for :users, controllers: {omniauth_callbacks: "omniauth_callbacks"}

see the difference?

like image 120
thomasfedb Avatar answered Nov 06 '22 08:11

thomasfedb


I am assuming that your users will be able to login and logout, edit profile, register with facebook or register with email and also you may add Confirmable to devise if you want. You should have extra columns in users table. Something like adding extra fields into your user model first.

rails g migration AddFieledsToUser provider:string uid:string image:string

then run rails db:migrate

Check your users table ensure you have these 3 columns above

Also I am assuming that you you have correctly configured initializers/devise.rb like so: config.omniauth :facebook, 'APP_ID', 'APP_SECRET_KEY', scope: 'email', info_fields: 'email, name' after you've properly created the facebook app. Also assuming you have properly created and configured your omniauth_callbacks_controller.rb based on the gems gem 'omniauth', '~> 1.6' and gem 'omniauth-facebook', '~> 4.0' in your gem file successfully. Just make sure you have all these steps done.

In your routes.rb you can add this:

devise_for :users,
         path: '',
         path_names: {
           sign_in: 'login',
           sign_out: 'logout',
           edit: 'profile',
           sign_up: 'registration'
         },
         controllers: {
           omniauth_callbacks: 'omniauth_callbacks',
         }

I think this is the part you have missed. You can also name the routes whatever you want. Just saying.

like image 25
Elias Glyptis Avatar answered Nov 06 '22 08:11

Elias Glyptis