我有一个问题,试图将 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
???
谢谢!
答案 0 :(得分:0)
问题解决了,我忘了在Javascript代码中设置window.location。 我改变了window.location后,它工作正常