Rspec2 和 Rails 3 - 查看嵌套资源的规范路由

发布于 2024-09-29 08:46:33 字数 358 浏览 1 评论 0原文

我有一个嵌套资源,设置如下:

 resources :chickens do
      resources :eggs
 end

EggsController 的视图位于views/eggs 下,但是:

describe "eggs/index.html.erb" do

给出了“没有路由匹配{:action => "create", :controller => "eggs"} 错误调用 render. 如何让 RSpec 找到视图规范的正确(嵌套)路由?

作为旁注,有没有办法为 Rails 3 控制器脚手架生成器指定嵌套资源?

I have a nested resource, setup like this:

 resources :chickens do
      resources :eggs
 end

The views for the EggsController are under views/eggs, but:

describe "eggs/index.html.erb" do

gives a "No route matches {:action => "create", :controller => "eggs"} error on calling render. How do I get RSpec to find the correct (nested) route for view specs?

As a side note, is there any way to specify a nested resource to the Rails 3 controller scaffold generator?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝天 2024-10-06 08:46:33

测试对我

来说看起来没问题...您的 Eggs/index.html.erb 上是否有一个表格用于创建可能尚未正确连接的新鸡蛋?看起来它可能正在尝试渲染索引视图但失败,因为该视图正在尝试构建一条不存在的路线?您需要确保表单使用正确的嵌套资源路由。当您将视图加载到浏览器中时,视图会呈现吗?

The test looks ok to me...

By any chance do you have a form on your eggs/index.html.erb for creating new eggs that might not yet be wired up correctly? It seems it may be trying to render the index view but failing because the view is trying build a route that doesn't exist? You'd want to make sure that the form is using the correct nested resource route. Does the view render when you load it up in the browser?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文