Rails 4 error with twitter / facebook authentication. develop

I am working with a device and I am trying to allow users to register using twitter / facebook. I am very confused because I keep getting \ No routes matched {: controller => "authentications" ,: action => "passthru" ,: provider =>: twitter ,: format => nil} missing keys: [: provider]

routes.rb

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

AuthenticationController.rb

 class AuthenticationsController < ApplicationController def index @authentications = Authentication.all end def create @authentication = Authentication.new(params[:authentication]) if @authentication.save redirect_to authentications_url, :notice => "Successfully created authentication." else render :action => 'new' end end def destroy @authentication = Authentication.find(params[:id]) @authentication.destroy redirect_to authentications_url, :notice => "Successfully destroyed authentication." end def twitter raise omni = request.env["omniauth.auth"].to_yaml end end 
+4
source share
2 answers

I assume that you have something like below in the User model; because of this you get this routing error.

 devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:facebook], :omniauth_providers => [:twitter] 

Change it to the following:

 devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:facebook, :twitter] 
+16
source

I followed omniauth on github and I had

 class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable devise :omniauthable, :omniauth_providers => [:google] end 

but you need to have only one development line as follows:

 class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:google] end 
+1
source

Source: https://habr.com/ru/post/1486142/


All Articles