ruby-on-rails-4 – Devise Omniauth,路由版本控制
发布时间:2020-12-16 21:22:57 所属栏目:百科 来源:网络整理
导读:我有一个模型候选人,设计omniauthable(linkedin). 到目前为止,我的routes.rb看起来像这样: namespace :v1 do devise_for :candidates,only: :omniauth_callbacks ...end 一切顺利,直到我不得不添加新版本: namespace :v2 do devise_for :candidates,only:
我有一个模型候选人,设计omniauthable(linkedin).
到目前为止,我的routes.rb看起来像这样: namespace :v1 do devise_for :candidates,only: :omniauth_callbacks ... end 一切顺利,直到我不得不添加新版本: namespace :v2 do devise_for :candidates,only: :omniauth_callbacks ... end namespace :v1 do devise_for :candidates,only: :omniauth_callbacks ... end 使用当前配置,我收到此错误: `set_omniauth_path_prefix!': Wrong OmniAuth configuration. If you are getting this exception,it means that either: (RuntimeError) 1) You are manually setting OmniAuth.config.path_prefix and it doesn't match the Devise one 2) You are setting :omniauthable in more than one model 3) You changed your Devise routes/OmniAuth setting and haven't restarted your server 这有点烦人,因为我希望能够在两个版本上验证候选者. 我能做什么 ? 解决方法
好吧,让我们回顾一下,Devise不允许你在config / routes.rb文件中定义的作用域或命名空间路由中调用devise_for方法,对吧?
我的命名空间路由如下所示: namespace :api,constraints: { format: :json } do devise_for :users,skip: [ :registrations,:passwords,:confirmations ] resources :profiles,only: :show end 它的工作原理! 我做了什么让它发挥作用?答案在于config / initializers / devise.rb文件. #使用omniauth时,Devise无法自动设置Omniauth路径, 下一个注释行显示一个示例,取消注释该行并根据您的需要对其进行修改,对于我的情况(即,对于我上面的命名空间路由)我有: config.omniauth_path_prefix = "/api/users/auth" 就是这样! ….我做到了,一切都开始完美! 希望能帮助到你! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容