我通过以下方式生成主页和联系人页面:
rails generate Pages home contact做了测试来验证,一切正常,现在我想添加页面“关于”。我通过复制和粘贴contact.html.erb,然后将其重命名为about.html.erb来创建about.html.erb。然后,我将内容从"Pages#contact“改为"Pages#about”。
我将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)>'我做错什么了?
我是否应该通过以下方式生成about页面:
rails generate Pages about来生成about页面?而不是复制-粘贴?
发布于 2010-11-20 11:50:38
也有同样的问题。在我的例子中,问题是'spork‘需要重新启动
发布于 2011-08-06 04:56:17
这是因为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发布于 2011-03-20 13:25:09
Samesies:重新启动spork
直到我沮丧地退出,并在一个小时后回来再看一眼,它才起作用。
https://stackoverflow.com/questions/3970733
复制相似问题