【问题标题】:omniauth + devise "user/auth/facebook" magic route questionomn​​iauth + 设计“user/auth/facebook”魔术路线问题
【发布时间】:2011-09-09 17:22:42
【问题描述】:

在 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 "*path" => "error#index", :constraints => lambda {|req| !req.path.starts_with?("/users/auth/") }

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

【问题讨论】:

    标签: ruby-on-rails-3 devise omniauth


    【解决方案1】:

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

    【讨论】:

    • 使用静态错误页面不能让你做一些事情,比如添加部分,包括你的应用程序布局......是的,状态代码包含在控制器操作的渲染调用中。
    • 刚碰到这个方法:railsapi.com/doc/rails-v3.0.8rc1/classes/ActiveSupport/…你应该可以捕捉到RecordNotFound。
    猜你喜欢
    • 2014-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 2012-01-06
    • 2011-10-06
    • 1970-01-01
    相关资源
    最近更新 更多