Boris Kuzevanov
Boris Kuzevanov

Reputation: 1302

Omniauth && devise no route

I trying to use omniauth to do login with social networks. I using this wiki but i have no success

There is my code:

Routes.rb

 get '/auth/:provider/callback', to: 'auth#create'

my auth controller:

class AuthController < ApplicationController
  def create
    p request.env['omniauth.auth']
  end

  def vkontakte

  end

  def facebook
  end
end

Why i have route error?

No route matches [GET] "/auth/vkontakte"

Thnks

Upvotes: 0

Views: 60

Answers (1)

oreoluwa
oreoluwa

Reputation: 5623

First, I think you have to do some config in your config/initializers/devise.rb.

config.omniauth :vkontakte, APP_ID, APP_SECRET The you need to add something like

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

with that you can implement the method in the

class OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def vkontakte
    # you can do anything you want to do here. Note that you have access to the `request.env["omniauth.auth"]` which holds all the user information you'd require.
  end
end 

One more thing: if you check the devise documentation, you'd find different configuration options, but always be careful not to overwrite/create AuthController because by default that's what Omniauth uses, I think and I believe in order to work with devise, you should be inheriting some stuff from Devise not ApplicationController.

Upvotes: 1

Related Questions