【发布时间】:2012-09-22 09:28:22
【问题描述】:
这是我的路线
match "/:type/:brand/:model/:plate" => "site/vehicles#show",
:constraints => {:plate => /[a-z]{3}\d{4}/}, :as => :vehicle
它通过了路由测试
# the route test passess
it "routes to #show" do
{:get => '/carro/volksvagen/gol-2-0/abc1234'}.should route_to(
"site/vehicles#show",
:type => "carro",
:brand => "volksvagen",
:model => "gol-2-0",
:plate => "abc1234"
)
end
但是在升级 rails (3.2.0 => 3.2.8 ) 并且更新了旅程 (1.0.0 => 1.0.4) 之后,以下 CONTROLLER 测试(恕我直言不应该检查路线,它显然没有,回到 rails 3.2.0) 开始失败。
describe "#show" do
it "should be success" do
get :show, :plate => @vehicle.plate
response.should be_success
end
end
上升
Site::VehiclesController#show should be success
ActionController::RoutingError:
No route matches {:plate=>"ABC1672", :controller=>"site/vehicles",
:action=>"show"}
即使我完成了所有的路线变量
describe "#show" do
it "should be success" do
get :show, :plate => @vehicle.plate, :model => 'model',
:type => 'type', :brand => 'brand'
response.should be_success
end
end
我明白了:
# No route matches {:plate=>"ABC1586", :model=>"model", :type=>"type",
:brand=>"brand", :controller=>"site/vehicles", :action=>"show"}
应用程序仍然可以运行,但我不知道它何时停止,因为我的测试失败了。
有人解决过/遇到过类似问题吗?
我知道“不升级 rails”可以避免出现此错误,正如在类似问题中所建议的那样,但我认为这不是一个解决方案。
Routing error when updating to Rails 3.2.6 or Rspec 2.11.0
提前谢谢你。
编辑:
vehicle /:type/:brand/:model/:plate(.:format) site/vehicles#show {:plate=>/[a-z]{3}\d{4}/}
【问题讨论】:
-
出于好奇,您为什么接受对同一个 URL 的 POST、PUT 和 DELETE 请求?
-
因为我是新手 =) 建议?
-
使用
get代替match,或使用:via选项。就个人而言,我认为指南应该完全放弃使用match作为主要路线动词。 guides.rubyonrails.org/routing.html#http-verb-constraints -
我把那里放在编辑下,@dpassage
标签: ruby-on-rails rspec routes journey