Omniauth error: No route matches [GET] “/auth/face

2019-09-04 17:11发布

问题:

My app was working fine three weeks ago, but upon returning to work on it I am getting this error after attempting to log in via Facebook:

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

Not sure what's going on. I've looked at Stackoverflow but found only help related to the Devise gem.

NOTE: I am not using the Devise gem.

My app is on Ruby 2.0 and Rails 4

My gemlock file is showing these versions of omniauth:

  oauth2 (0.8.1)
      faraday (~> 0.8)
      httpauth (~> 0.1)
      jwt (~> 0.1.4)
      multi_json (~> 1.0)
      rack (~> 1.2)
    omniauth (1.1.4)
      hashie (>= 1.2, < 3)
      rack
    omniauth-facebook (1.4.0)
      omniauth-oauth2 (~> 1.0.2)
    omniauth-oauth2 (1.0.3)
      oauth2 (~> 0.8.0)
      omniauth (~> 1.0) 

Here is my routes.rb:

Mybrary::Application.routes.draw do
  get "sessions/create"
  get "sessions/destroy"
  resources :users do
    resources :items, except: [:index]
  end


  resources :groups
  root 'users#splash'


  get 'items/search' => 'items#search_results', as: :search_item

  post 'user/:id/requests/:item_id' => 'users#request_loan', as: :request_loan
  post 'user/:id/approves/:item_id' => 'users#approve_loan', as: :approve_loan
  post 'user/:id/denies/:item_id' => 'users#deny_loan', as: :deny_loan
  post 'user/:id/returns/:item_id' => 'users#return_loan', as: :return_loan

  post 'group/:id/join_group/:user_id' => 'groups#join_group', as: :join_group
  post 'group/:id/leave_group/:user_id' => 'groups#leave_group', as: :leave_group

  post 'group/:id/approve_member/:user_id' => 'groups#approve_member', as: :approve_member
  post 'group/:id/deny_member/:user_id' => 'groups#deny_member', as: :deny_member


  match 'auth/:provider/callback', to: 'sessions#create', via: [:get, :post]
  match 'auth/failure', to: redirect('/'), via: [:get, :post]
  match 'signout', to: 'sessions#destroy', as: 'signout', via: [:get, :post]
end

回答1:

Instead of this one

match 'auth/:provider/callback', to: 'sessions#create', via: [:get, :post]
match 'auth/failure', to: redirect('/'), via: [:get, :post]
match 'signout', to: 'sessions#destroy', as: 'signout', via: [:get, :post]

try this one

 get 'auth/:provider/callback' => 'sessions#create'
 get 'auth/failure' => redirect('/')
 get 'signout' => 'sessions#destroy', as: 'signout'