Ruby on rails 单一资源上rspec测试桩的失配路由

Ruby on rails 单一资源上rspec测试桩的失配路由,ruby-on-rails,ruby,testing,rspec,Ruby On Rails,Ruby,Testing,Rspec,我得到的错误是,即使在rake路由中,也没有匹配的路由: 。。。POST/todo/:todo/todo_注释:格式 在我的简历里我有 post:todo_comments,params:{todo_id:1}听起来您的路由定义如下: resources :todos do resources :todo_comments end 在controller spec type::controller中,需要在处理请求的控制器中指定操作名称。在这种情况下,即:索引: 另一方面,如果您在requ

我得到的错误是,即使在rake路由中,也没有匹配的路由:

。。。POST/todo/:todo/todo_注释:格式

在我的简历里我有


post:todo_comments,params:{todo_id:1}

听起来您的路由定义如下:

resources :todos do
  resources :todo_comments
end
在controller spec type::controller中,需要在处理请求的控制器中指定操作名称。在这种情况下,即:索引:

另一方面,如果您在request spec type::request中,则需要URL来进行请求,您可以使用路由帮助器生成URL:

post todo_todo_comments_path(1)

# or, without the helper:
post "/todos/1/todo_comments"
请注意,这些表单没有显式地命名:todo_id参数,因为它将从路由中提取。

是否应该使用路径?,todo_注释只是前缀。
post todo_todo_comments_path(1)

# or, without the helper:
post "/todos/1/todo_comments"