我正在编写一个功能测试,但它失败并出现以下错误:
1) Failure:
test: routing should route GET /categories/1/inventory_items/2/edit to/from {:action=>"edit", :controller=>"inventory_items", :category_id=>"1", :id=>"2"}. (InventoryItemsControllerTest)
[]:
No route matches "/categories/1/inventory_items/2/edit"
有路线:
resources :categories, :constraints => lambda { |request| Category.exists?(request.params['category_id']) } do
resources :inventory_items
end
和我的佣金路线:
category_inventory_items GET /categories/:category_id/inventory_items(.:format) inventory_items#index
POST /categories/:category_id/inventory_items(.:format) inventory_items#create
new_category_inventory_item GET /categories/:category_id/inventory_items/new(.:format) inventory_items#new
edit_category_inventory_item GET /categories/:category_id/inventory_items/:id/edit(.:format) inventory_items#edit
category_inventory_item GET /categories/:category_id/inventory_items/:id(.:format) inventory_items#show
PUT /categories/:category_id/inventory_items/:id(.:format) inventory_items#update
DELETE /categories/:category_id/inventory_items/:id(.:format) inventory_items#destroy
我尝试创建一个Category
的{{1}}对象,但它仍然失败。我在路线中执行了:id
,puts
哈希是params
!我正在使用像这样的应用匹配器:
{}
当我在匹配器中执行should route(:get, "/categories/1/inventory_items/2").to(:action => "show", :controller => "inventory_items", :category_id => 1, :id => 2)
时,puts
已正确填充:
params
感谢任何帮助,谢谢!