简体   繁体   English

test_should_get_show(CartsControllerTest):ActionController :: RoutingError:没有路线匹配{:cart =>“ 1”,:controller =>“ carts”,:action =>“ show”}

[英]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.

相关问题 ActionController :: RoutingError(没有路由与{:action =>“ show”,:controller =>“ users”,:id => nil}匹配): - ActionController::RoutingError (No route matches {:action=>“show”, :controller=>“users”, :id=>nil}): Ruby On Rails:ActionController :: RoutingError没有路线匹配,动作显示 - Ruby On Rails: ActionController::RoutingError No route matches, action show ActionController :: RoutingError:没有路由与{:controller =>“ vendors”,:action =>“ vendors”}匹配? - ActionController::RoutingError: No route matches {:controller=>“vendors”, :action=>“vendors”}? ActionController :: RoutingError(没有路由匹配{:controller =>“users”,:action =>“profile”}) - ActionController::RoutingError (No route matches {:controller=>“users”, :action=>“profile”}) ActionController :: RoutingError(没有路由与[GET]匹配 - ActionController::RoutingError (No route matches [GET] " 没有路由匹配[GET]“ /”(ActionController :: RoutingError) - No route matches [GET] “/” (ActionController::RoutingError) ActionController :: RoutingError:没有路由与[GET]“ /”匹配 - ActionController::RoutingError: No route matches [GET] “/” ActionController :: RoutingError-没有路由匹配 - ActionController::RoutingError - No route matches ActionController :: RoutingError(没有路由匹配 - ActionController::RoutingError (No route matches 没有路由匹配{:action =>“ show”,:controller =>“ carts”,:id => nil},缺少必需的键:[:id] - No route matches {:action=>“show”, :controller=>“carts”, :id=>nil}, missing required keys: [:id]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM