Devise Omniauth-facebook没有路线匹配[GET]“/ users / auth / facebook / callback”

时间:2013-07-17 22:30:36

标签: devise routes omniauth ruby-on-rails-4

我有一个问题,试图将 omniauth-facebook 设计一起使用 我跟着这个railscast video(只用twitter取代推特)并且能够让它发挥作用。 但是,我想稍微自定义我的路线,所以这就是我做的:

配置/ routes.rb中

devise_for :users, path: 'accounts', 
           controllers: { omniauth_callbacks: "omniauth_callbacks" },
           path_names: { sign_in: "login", sign_out: "logout", sign_up: "signup" }

应用/控制器/ omniauth_callbacks_controller.rb

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def all
    user = User.from_omniauth(request.env["omniauth.auth"])
    if user.persisted?
      flash.notice = "Successfully signed in via #{request.env["omniauth.auth"].provider}!"
      sign_in_and_redirect user
    else
      session["devise.user_attributes"] = user.attributes
      redirect_to new_user_registration_url
    end
  end
  alias_method :facebook, :all
end

正如我所料,在我的网址“users / ...”被更改为“accounts / ...”,但当我尝试通过facebook登录时,我收到此错误: Routing Error No route matches [GET] "/users/auth/facebook/callback"

在玩完它之后,我通过添加这一行来解决它:

配置/ routes.rb中

get '/users/auth/facebook/callback', to: redirect('/accounts/auth/facebook/callback')

现在工作正常,但我认为必须有更好的解决方案。

有没有办法将返回的回调网址从/users/auth/facebook/callback更改为/accounts/auth/facebook/callback ???

谢谢!

1 个答案:

答案 0 :(得分:0)

问题解决了,我忘了在Javascript代码中设置window.location。 我改变了window.location后,它工作正常