1

我关注了Rails Casts Episode #360,了解如何集成 facebook 登录。

当我单击“使用 Facebook 登录”时,出现以下错误:

Routing Error

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

这是我的路线文件:

Frostfiress::Application.routes.draw do
  ActiveAdmin.routes(self)

  devise_for :admin_users, ActiveAdmin::Devise.config

  get "profiles/show"
  #get 'questions/:tag', to: 'questions#index', as: :tag
  #get 'places/:tag', to: 'places#index', as: :tag
  match 'auth/:provider/callback', to: 'sessions#create'
  match 'auth/failure', to: redirect('/')
  match 'signout', to: 'sessions#destroy', as: 'signout'

  resources :places


  devise_for :users

  devise_scope :user do 
      get 'register', to: 'devise/registrations#new', as: :register
      get 'login', to: 'devise/sessions#new', as: :login
      get 'logout', to: 'devise/sessions#destroy', as: :logout
      get 'password/change', to: 'devise/passwords#edit', as: :password
  end

  resources :answers

  resources :questions


  root :to => "questions#index"

  get '/:username', to: 'profiles#show'

我必须在 RailsCast 中更改的所有其他文件都与教程中的完全相同。

我的 AppId 和 Secret 正在工作,但现在我收到路由错误。

有什么建议么?

谢谢

这是 rake 路由的结果:

profiles_show GET        /profiles/show(.:format)                  profiles#show
                                          /auth/:provider/callback(.:format)        sessions#create
                  auth_failure            /auth/failure(.:format)                   :controller#:action
                       signout            /signout(.:format)                        sessions#destroy
                        places GET        /places(.:format)                         places#index
                               POST       /places(.:format)                         places#create
                     new_place GET        /places/new(.:format)                     places#new
                    edit_place GET        /places/:id/edit(.:format)                places#edit
                         place GET        /places/:id(.:format)                     places#show
                               PUT        /places/:id(.:format)                     places#update
                               DELETE     /places/:id(.:format)                     places#destroy
              new_user_session GET        /users/sign_in(.:format)                  devise/sessions#new
                  user_session POST       /users/sign_in(.:format)                  devise/sessions#create
          destroy_user_session DELETE     /users/sign_out(.:format)                 devise/sessions#destroy
       user_omniauth_authorize            /users/auth/:provider(.:format)           devise/omniauth_callbacks#passthru {:provider=>/(?!)/}
        user_omniauth_callback            /users/auth/:action/callback(.:format)    devise/omniauth_callbacks#(?-mix:(?!))
                 user_password POST       /users/password(.:format)                 devise/passwords#create
             new_user_password GET        /users/password/new(.:format)             devise/passwords#new
            edit_user_password GET        /users/password/edit(.:format)            devise/passwords#edit
                               PUT        /users/password(.:format)                 devise/passwords#update
      cancel_user_registration GET        /users/cancel(.:format)                   devise/registrations#cancel
             user_registration POST       /users(.:format)                          devise/registrations#create
         new_user_registration GET        /users/sign_up(.:format)                  devise/registrations#new
        edit_user_registration GET        /users/edit(.:format)                     devise/registrations#edit
                               PUT        /users(.:format)                          devise/registrations#update
                               DELETE     /users(.:format)                          devise/registrations#destroy
                      register GET        /register(.:format)                       devise/registrations#new
                         login GET        /login(.:format)                          devise/sessions#new
                        logout GET        /logout(.:format)                         devise/sessions#destroy
                      password GET        /password/change(.:format)                devise/passwords#edit
                       answers GET        /answers(.:format)                        answers#index
                               POST       /answers(.:format)                        answers#create
                    new_answer GET        /answers/new(.:format)                    answers#new
                   edit_answer GET        /answers/:id/edit(.:format)               answers#edit
                        answer GET        /answers/:id(.:format)                    answers#show
                               PUT        /answers/:id(.:format)                    answers#update
                               DELETE     /answers/:id(.:format)                    answers#destroy
                     questions GET        /questions(.:format)                      questions#index
                               POST       /questions(.:format)                      questions#create
                  new_question GET        /questions/new(.:format)                  questions#new
                 edit_question GET        /questions/:id/edit(.:format)             questions#edit
                      question GET        /questions/:id(.:format)                  questions#show
                               PUT        /questions/:id(.:format)                  questions#update
                               DELETE     /questions/:id(.:format)                  questions#destroy
                          root            /                                         questions#index
                               GET        /:username(.:format)                      profiles#show
4

1 回答 1

-1

路由 /auth/facebook 不是自动生成的,如果它在那里,除非你将它映射到某个控制器函数,否则它实际上不会做任何事情。但是,您不需要这样做。

确保您实际上是在向 facebook 发送请求,否则omniauth 将无法执行任何操作。

http://developers.facebook.com/docs/howtos/login/getting-started/

您应该通过在成功时重定向到 /auth/facebook/callback 或在失败时重定向到 /auth/failure 来处理 facebook 对您的请求的响应。

于 2013-03-06T00:55:13.843 回答