黄瓜的路由问题

发布于 2024-09-16 02:47:53 字数 377 浏览 6 评论 0原文

我正在使用 Rails 3 和 Cucumber,除了这个小问题之外一切都很顺利

Given I am on the "edit automobile" page
  No route matches {:controller=>"automobiles", :action=>"edit"} (ActionController::RoutingError)

现在路径在 paths.rb 中设置为 edit_automobile_path

并在 paths.rb 中我有汽车作为资源,我搭建了它

,所以请告诉我什么我失踪了,显然路线已定义并匹配,因为我运行了 rake 路线并看到了路线。

请给我指出正确的方向

I am working with rails 3 and cucumber, all is going well except for this little problem

Given I am on the "edit automobile" page
  No route matches {:controller=>"automobiles", :action=>"edit"} (ActionController::RoutingError)

Now the path is set in paths.rb as edit_automobile_path

and in the routes.rb I have automobiles as a resource, I scaffolded it

so please tell me what I am missing, clearly the route is defined and matches, because I ran rake routes and saw the route.

please point me in the right direction

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

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

发布评论

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

评论(4

您可以在功能文件中按照如下所述进行操作:

Given I have an automobile
Then I want to visit edit automobile page for "automob"

然后在步骤定义文件中:

Then(/^I want to visit edit automobile page for "(.*?)"$/) do |auto|
 vehicle = Automobile.find_by_name(auto)
 visit edit_automobile_path(vehicle.id)
end

You can do it as mentioned below in your feature file :

Given I have an automobile
Then I want to visit edit automobile page for "automob"

Then in your step definition file:

Then(/^I want to visit edit automobile page for "(.*?)"$/) do |auto|
 vehicle = Automobile.find_by_name(auto)
 visit edit_automobile_path(vehicle.id)
end
a√萤火虫的光℡ 2024-09-23 02:48:02

如果您想编辑特定的汽车,我想您可以在 paths.rb 中使用以下内容:

when /^the edit automobile for "automobile1"$/
  edit_automobile_path(Automobile.find_by_name(page_name.scan(/\"([^"]+)/)))

因此它将 automobile1 作为参数传递给 find_by_name()

In case you want to edit a particular automobile, I guess you can use the following within paths.rb:

when /^the edit automobile for "automobile1"$/
  edit_automobile_path(Automobile.find_by_name(page_name.scan(/\"([^"]+)/)))

so it passes the automobile1 as a parameter to find_by_name().

此生挚爱伱 2024-09-23 02:48:01

在您的功能文件中,您可以执行以下操作:

Given I have an automobile
Then I want to visit edit automobile page for "automobile1"

然后在您的步骤定义文件中:

Then(/^I want to visit edit automobile page for "(.*?)"$/) do |auto|
 automobile = Automobile.find_by_name(auto)
 visit edit_automobile_path(automobile.id)
end

In your feature file you can do something like this :

Given I have an automobile
Then I want to visit edit automobile page for "automobile1"

Then in your step definition file:

Then(/^I want to visit edit automobile page for "(.*?)"$/) do |auto|
 automobile = Automobile.find_by_name(auto)
 visit edit_automobile_path(automobile.id)
end
岛徒 2024-09-23 02:47:59

在您的features/support/paths.rb 文件中,这样的路径指定了您需要向edit_automobile_path 传递一个ID 的唯一资源,

在您的rake 路由中,它将看起来像 automobiles/:id/edit

所以你需要有 edit_automobile_path(:id)

为了在黄瓜中做到这一点,假设你有类似的东西

Given I have an automobile
And I am on the 'edit automobile' page

在你给定的步骤 def 声明一个变量 @automobile = Automobile.create()

然后在 paths.rb 文件中

when /edit automobile page/
  edit_automobile_path @automobile
...

In your features/support/paths.rb file for a path like this that specifies a unique resource you need to pass your edit_automobile_path an id,

in your rake routes it will look like automobiles/:id/edit

so you need to have edit_automobile_path(:id)

In order to do this in cucumber assume you have something like

Given I have an automobile
And I am on the 'edit automobile' page

In your given step def declare a variable @automobile = Automobile.create()

And then in your paths.rb file

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