2015-12-19 47 views
0

我有2種方法登錄到我的應用程序。第一種方法是通過電子郵件登錄下一個是通過社交媒體登錄。未找到軌道

我已經安裝了devise和omniauth,omniauth-facebook,twitter和google plus。我已經成功地通過設計實現了正常登錄,但是當我嘗試通過訪問/ auth/facebook通過fb或twitter或gplus登錄時,它說未找到路由。

Rails.application.routes.draw do 
    devise_for :users 
    root to: 'visitors#index' 
    get '/auth/:provider/callback' => 'sessions#create' 
    get '/signin' => 'sessions#new', as: :signin 
    get '/signout' => 'sessions#destroy', as: :signout 
    get '/auth/failure' => 'sessions#failure' 
end 

//session_controller.rb

class SessionsController < ApplicationController 
    def new 
    redirect_to '/auth/facebook' 
    end 

    def create 
    auth = request.env['omniauth.auth'] 
    user = User.where(provider: auth['provider'], 
         uid: auth['uid'].to_s).first || User.create_with_omniauth(auth) 
    reset_session 
    session[:user_id] = user.id 
    redirect_to root_url, notice: 'Signed in!' 
    end 

    def destroy 
    reset_session 
    redirect_to root_url, notice: 'Signed out!' 
    end 

    def failure 
    redirect_to root_url, alert: "Authentication error: #{params[:message].humanize}" 
    end 
end 

//omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do 
    provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], 
      scope: 'public_profile', info_fields: 'id,name,link' 
    provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] 
    provider :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_SECRET'], 
      scope: 'profile', image_aspect_ratio: 'square', image_size: 48, 
      access_type: 'online', name: 'google' 
end 

回答

1

取消對

devise :database_authenticatable, :registerable, 
    :recoverable, :rememberable, :trackable, :validatable, 
    :confirmable, :lockable, :timeoutable //, :omniauthable 
在user.rb

的伎倆