我有一个问题将尝试将omniauth-facebook与设计一起使用 我遵循了这个railscast 视频(只需用facebook 替换twitter)并且能够让它工作。但是,我想稍微自定义一下我的路线,所以这就是我所做的:
配置/路由.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
正如我所料,在我的 url 中“users/...”被更改为“accounts/...”,但是当我尝试通过 facebook 登录时,我收到了这个错误:
Routing Error
No route matches [GET] "/users/auth/facebook/callback"
在玩弄它之后,我通过添加以下行来解决它:
配置/路由.rb
get '/users/auth/facebook/callback', to: redirect('/accounts/auth/facebook/callback')
它现在工作正常,但我认为必须有更好的解决方案。
有什么方法可以将返回的回调 url 从更改/users/auth/facebook/callback
为/accounts/auth/facebook/callback
???
谢谢!