开发者

omniauth + devise "user/auth/facebook" magic route question

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 {|r开发者_StackOverflow中文版eq| !req.path.starts_with?("/users/auth/") }

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


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜