[英]test_should_get_show(CartsControllerTest): ActionController::RoutingError: No route matches {:cart=>“1”, :controller=>“carts”, :action=>“show”}
The error I keep getting is as follows: 我不断收到的错误如下:
test_should_get_show(CartsControllerTest):
ActionController::RoutingError: No route matches {:cart=>"1", :controller=>"carts", :action=>"show"}
When I run the following code: 当我运行以下代码时:
def setup
@cart = FactoryGirl.create(:cart)
end
test "should get show" do
sign_in(FactoryGirl.create(:user, admin: true))
session[:cart_id] = @cart.id
get :show, cart: @cart
assert_response :success
assert_not_nil assigns(:product_requests)
end
My cart factory: 我的购物车工厂:
FactoryGirl.define do
factory :cart do
factory :cart_with_1_row do
after(:create) do |cart|
FactoryGirl.create(:cart_row, cart: cart)
end
end
end
end
However, in my rake routes I have: 但是,在我的耙路中,我有:
cart GET /carts/:id(.:format) carts#show
I can also go to http://localhost:3000/carts/1
manually in the browser in the development environment and it works fine. 我还可以在开发环境中的浏览器中手动转到http://localhost:3000/carts/1
,它可以正常工作。
What could be causing this? 是什么原因造成的?
Replace: 更换:
get :show, cart: @cart
With: 带有:
get :show, id: @cart # or @cart.id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.