简体   繁体   English

ActionController :: RoutingError:没有路由与{:controller =>“ vendors”,:action =>“ vendors”}匹配?

[英]ActionController::RoutingError: No route matches {:controller=>“vendors”, :action=>“vendors”}?

In my test, I'm trying to call 在测试中,我正在尝试致电

get :vendors

but the error I get is 但是我得到的错误是

ActionController::RoutingError: No route matches {:controller=>"vendors", 
    :action=>"vendors"}

I do have the following in routes.rb 我在routes.rb中确实有以下内容

match '/vendors', :to => 'vendors#index'

so I don't get why it's looking for the (non-existent) "vendors" action instead of using "index" like it's matched. 所以我不明白为什么它要寻找(不存在的)“供应商”行动,而不是像匹配的那样使用“索引”。 Can anyone explain this to me? 有人可以向我解释吗?

Because you told it to? 因为你告诉过吗?

The test is already contextualized, presumably with describe VendorsController , so saying get :vendors tells it to get the Vendors#vendors action. 该测试已经进行describe VendorsController ,大概是在describe VendorsController进行了describe VendorsController ,因此说get :vendors告诉它获得Vendors#vendors动作。 It isn't saying "get the /vendors URL", it's going straight to the controller. 并不是说“获取/ vendors URL”,而是直接进入控制器。

In general, you run get :action not get :controller nor get :matched_route_name 通常,您运行get :action而不是get :controllerget :matched_route_name

you should be doing 你应该在做

get :index

Here is an example of controller test in rspec 是rspec中的控制器测试的示例

暂无
暂无

声明:本站的技术帖子网页,遵循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}): ActionController :: RoutingError(没有路由匹配{:controller =>“users”,:action =>“profile”}) - ActionController::RoutingError (No route matches {:controller=>“users”, :action=>“profile”}) ActionController :: RoutingError-没有路由匹配 - ActionController::RoutingError - No route matches ActionController :: RoutingError(没有路由匹配 - ActionController::RoutingError (No route matches 设计命名空间 - ActionController :: RoutingError(无路由匹配{:action =>“new”,:controller =>“devise / sessions”}) - Devise in namespace - ActionController::RoutingError (No route matches {:action=>“new”, :controller=>“devise/sessions”}) ActionController :: RoutingError:没有路由与{:period_registration => {},:controller =>“ period_registrations”,:action =>“ save_period”}匹配 - ActionController::RoutingError: No route matches {:period_registration=>{}, :controller=>“period_registrations”, :action=>“save_period”} 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”} ActionController :: RoutingError(没有路由与[GET]匹配 - ActionController::RoutingError (No route matches [GET] " ActionController :: RoutingError(没有路线与[DELETE]匹配 - ActionController::RoutingError (No route matches [DELETE] ActionController :: RoutingError没有路由匹配[DELETE] - ActionController::RoutingError No route matches [DELETE]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM