我正在将旧应用程序转换为Rails 3.1。新的应用程序使用,它提供了水珠路线发动机:如何覆盖Rails 3.1使用带glob路由引擎时的“路由错误”?
# myengine/config/routes.rb
Rails.application.routes.draw do
match 'foo/bar/*path' => 'myengine/foobar#index', :format => false
end
继承应用程序使用的最终包罗万象通配符路线否则匹配的路由提供自定义处理(而不是熟悉的Rails的“路由错误”页):
# myapp/config/routes.rb
Myapp::application.routes.draw do
# ...
match '*path' => 'failures#index', :format => false
end
不知怎的,这个catchall路线干扰发动机的路线。如果我评论应用程序的catchall路线,引擎的路线工作正常。但是,如果我留在发动机的路线永远没有匹配和应用程序对failures#index
包罗万象的路线来代替:
Started GET "/foo/bar//projects/x/vol1/prod22/9907042031/9907042031.aff/ImageProperties.xml" for 10.71.1.136 at 2011-08-02 15:46:48 -0700
Processing by FailuresController#index as JS
Parameters: {"path"=>"foo/bar/projects/x/vol1/prod22/9907042031/9907042031.aff/ImageProperties.xml"}
Rendered failures/index.html.erb within layouts/application (0.0ms)
Completed 200 OK in 47ms (Views: 46.9ms)
一个人怎么会重写而不会破坏引擎路由默认的Rails 3.1的路由错误处理程序?
好问题。顺便说一句,Rails 3全部路径可以格式化为:'match'* path',:to =>'docs#not_found'' now – iwasrobbed
你试过了吗? http://apidock.com/rails/ActiveSupport/Rescuable/ClassMethods/rescue_from – bor1s
看来这种行为是Rails 3.x中的一个已知错误(请参阅Andre Andre Pankratz 2011年3月19日的评论:https://rails.lighthouseapp。 com/projects/8994/tickets/4444-can-no-longer-rescue-from-actioncontrollerroutingerror)和他在这里讨论bug的宝石(https://github.com/vidibus/vidibus-routing_error) – jwfearn