在 rails 中找不到路线
Routes not found in rails
我有 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
取消注释
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, :lockable, :timeoutable //, :omniauthable
在 user.rb 中成功了
我有 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
取消注释
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, :lockable, :timeoutable //, :omniauthable
在 user.rb 中成功了