我通过以下方式生成了家庭和联系页面:
rails generate Pages home contact
做了测试验证,一切都没问题,现在我想添加页面“about”。我通过复制contact.html.erb并粘贴然后将其重命名为about.html.erb来创建about.html.erb。然后我将内容更改为“Pages#about”而不是“Pages#contact”
我将route.rb更改为:
SampleApp::Application.routes.draw do
get "pages/home"
get "pages/contact"
get "pages/about"
然后pages_controller.rb到:
def home
end
def contact
end
def about
end
最后将此添加到pages_controller_spec.rb:
describe "GET 'about'" do
it "should be successful" do
get 'about'
response.should be_success
end
end
在我的自动测试中,这是错误:
Failures:
1) PagesController GET 'about' should be successful
Failure/Error: get 'about'
No route matches {:controller=>"pages", :action=>"about"}
# ./spec/controllers/pages_controller_spec.rb:22:in `block (3 levels) in <top (required)>'
我做错了什么?
我是否应该通过以下方式生成关于页面:
rails generate Pages about
生成关于页面?而不是复制粘贴?
答案 0 :(得分:5)
有同样的问题。 在我的情况下,问题是“spork”需要重新启动
答案 1 :(得分:2)
这是因为spork不会重新加载你的路线。把它放在你的spec_helper.rb中以强制spork重新加载路线“each_run”(信用:http://jinpu.wordpress.com/2011/03/13/reload-routes-with-spork-each-run/)
Spork.each_run do
# This code will be run each time you run your specs.
require File.expand_path("../../config/routes", __FILE__)
end
答案 2 :(得分:0)
Samesies:重启spork
只有在我沮丧地退出并且在一小时后回来再看看它是否有效之后。