我已经定义了一个自定义路由 路线.rb
get "packages/city/:location_id", to: "packages#index"
在 controller_spec.rb
中,
get :index
给出这个错误,
ActionController::UrlGenerationError:
No route matches {:action=>"index", :controller=>"packages"}
如何在 Controller 规范中明确指定自定义路由?
最佳答案
如果您这样声明您的路线,也许它会有所帮助?
get "packages/city/:location_id" => "packages#index"
请记住在规范中提供一个 location_id
参数,例如获取 :index, location_id: 1
。
关于ruby-on-rails - 如何使用 rspec 在 Controller 中测试自定义路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29273813/