黄瓜

2010-08-26 168 views
5

路由问题,我与轨道3和黄瓜的工作,除了这个小问题黄瓜

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

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

,并在一切都进展顺利routes.rb我有汽车作为一种资源,我脚手架它

所以请告诉我什么,我失踪,显然路线定义和匹配,因为我跑耙路线,看到了路线。

请点我在正确的方向

回答

9

在你features/support/paths.rb文件,指定你需要通过你的edit_automobile_path ID的独特的资源这样的路径,你耙路线就会像

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 
... 
+0

非常感谢你为此,我仍然在学习,谢谢,谢谢,谢谢,好吧,回去工作 – creativeKoder 2010-08-26 17:35:22

+1

没有问题。不要忘了,如果这个模型变成了一个嵌套的资源,你将不得不指定:automobile_id或其他什么,因为它不知道要查找的id,所以你将不得不改变paths.rb中的调用来处理它。 – 2010-08-26 17:55:21

1

如果你想编辑特定的汽车,我想你可以使用以下内径paths.rb:

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

所以它通过automobile1作为参数find_by_name()

2

在您的特性文件,你可以做这样的事情:

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 
+0

感谢rupali这解决了我的问题。 – 2014-05-15 08:06:06

1

你可以做到这一点,如你有文件提到如下:

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