全方位认证 +设计“user/auth/facebook”魔法路线问题

发布于 2024-12-03 13:34:05 字数 935 浏览 0 评论 0原文

在 Rails 3 应用程序上,我定义了这些路由:

    devise_for :users, :controllers => {:omniauth_callbacks => "users/omniauth_callbacks", :registrations => 'registrations'}, :path_names => { :sign_in => 'login', :sign_out => 'logout' } do
      get 'login' =>'devise/sessions#new', :as => :new_user_session
      post 'login' => 'devise/sessions#create', :as => :user_session
      get 'signup'  => 'registrations#new', :as => :new_user_registration
      get 'signout' => 'devise/sessions#destroy', :as => :destroy_user_session
    end

    # catchall route to deal with routing errors
    match "*path" => "error#index"

但是,现在当我去登录 /user/auth/facebook 时,它会将我路由到错误页面...

我的解决方案是向最终添加约束match:

    match "*path" => "error#index", :constraints => lambda {|req| !req.path.starts_with?("/users/auth/") }

这可行,但我想知道是否有更好的方法......?

On a rails 3 app, I've got these routes defined:

    devise_for :users, :controllers => {:omniauth_callbacks => "users/omniauth_callbacks", :registrations => 'registrations'}, :path_names => { :sign_in => 'login', :sign_out => 'logout' } do
      get 'login' =>'devise/sessions#new', :as => :new_user_session
      post 'login' => 'devise/sessions#create', :as => :user_session
      get 'signup'  => 'registrations#new', :as => :new_user_registration
      get 'signout' => 'devise/sessions#destroy', :as => :destroy_user_session
    end

    # catchall route to deal with routing errors
    match "*path" => "error#index"

However, now when I go to log /user/auth/facebook, it routes me to the errors page...

My solution to this was to add constraints to the final match:

    match "*path" => "error#index", :constraints => lambda {|req| !req.path.starts_with?("/users/auth/") }

This works, but I am wondering if there is a better way... ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

快乐很简单 2024-12-10 13:34:05

我认为你最好让 404 页面处理路由错误。在开发过程中你只会遇到 500 错误。这是正在生产的 404。例如在我的网站上:http://agmprojects.com/test。所以我建议使用公共文件夹中的 404.html,而不是加载该控制器。出于好奇,您是否使用 404 http 状态代码进行响应?

I think you are better off letting a 404 page handle routing errors. You only get a 500 error in development. It's a 404 in production. For example on my site: http://agmprojects.com/test. So i suggest using the 404.html in the public folder instead, rather than loading that controller. Out of curiosity, are you responding with a 404 http status code?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文