我有一个非常复杂的路由方案,当我使用控制台对其进行测试时一切都很好,但在生产中爆炸并出现路由错误:没有路由匹配。
路线
resources :sports, :only => [ :show ] do
member do
get ':page', :to => 'sports#facilities'
end
end
resources :provinces, :path => '', :only => [ :show ] do
resources :municipalities, :path => '', :only => [ :show ] do
resources :neighbourhoods, :path => '', :only => [ :show ] do
resources :sports, :only => [ :show ] do
member do
get ':page', :to => 'sports#facilities'
end
end
end
resources :sports, :only => [ :show ] do
member do
get ':page', :to => 'sports#facilities'
end
end
end
resources :sports, :only => [ :show ] do
member do
get ':page', :to => 'sports#facilities'
get 'deals'
end
end
end
这就是我要查看路线是否被正确识别的方法:
1.9.3p194 :001 > r = Rails.application.routes
=> #<ActionDispatch::Routing::RouteSet:0x007fa7f3a0edb0>
1.9.3p194 :002 > r.recognize_path( '/milano/milano/sports/tennis' )
=> {:action=>"show", :controller=>"sports", :province_id=>"milano", :municipality_id=>"milano", :id=>"tennis"}
1.9.3p194 :003 > r.recognize_path( '/milano/milano/sports/tennis/1' )
=> {:controller=>"sports", :action=>"facilities", :province_id=>"milano", :municipality_id=>"milano", :id=>"tennis", :page=>"1"}
1.9.3p194 :004 > r.recognize_path( '/sports/tennis/1' )
=> {:controller=>"sports", :action=>"facilities", :id=>"tennis", :page=>"1"}
当我在生产中尝试相同的操作时,我看到 :page 为 nil,并且路径无法识别。这是完全相同的页面。更奇怪的是,如果页面有语法错误或其他什么,它引发的异常是页面内部引发的异常,当我修复它时,我有一个路由错误......
传递给控制器的参数是 {:controller=>"sports", :action=>"facilities", :id=>"tennis", :page=>nil},即使我使用 / 2 /3。
有人经历过这样的事情,可以帮助我吗?
导轨是 3.2.7
提前致谢。