Finnnn
Finnnn

Reputation: 3580

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

Upvotes: 12

Views: 7137

Answers (3)

Elias Glyptis
Elias Glyptis

Reputation: 530

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.

Upvotes: 1

James Mosier
James Mosier

Reputation: 21

I ran into a similar problem with tutorials. Check the capitalization of F in facebook in users/omniauth_callbacks_controller.rb I was using a capital "Facebook" but it was looking for lowercase "facebook"

Upvotes: 0

thomasfedb
thomasfedb

Reputation: 5983

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?

Upvotes: 17

Related Questions