好吧...在发布这个问题时有点犹豫不决但是这里有:
它实际上很像question。
我的规格测试也失败了...但是我并不太关心b / c它只涉及所有页面的标题......(我可以轻松修复)
我真正想知道的是路线问题。
跟随section 5.3.2 rail routes中所有哈特尔的指示后,这就是我得到的:
No route matches [GET] "/static_pages/about"
No route matches [GET] "/static_pages/home"
No route matches [GET] "/static_pages/help"
No route matches [GET] "/static_pages/contact"
config / routes.rb设置
SampleApp::Application.routes.draw do
root to: 'static_pages#home'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
我可以通过在'/ help','/ about'和'/ contact'前加上'static_pages'前缀来修复上面的三个页面......
它仍然无法解决主页问题。
将此添加到spec_helper.rb没有帮助(来自链接)
config.include Rails.application.routes.url_helpers
我在这里缺少什么,还需要添加哪些其他信息才能使问题更加清晰?
测试由以下语句完成:bundle exec rspec spec / requests / static_pages_spec.rb
这是运行语句后的终端
Failures:
1) Static pages About page should have the h1 'About Us'
Failure/Error: visit '/static_pages/about'
ActionController::RoutingError:
No route matches [GET] "/static_pages/about"
# ./spec/requests/static_pages_spec.rb:46:in `block (3 levels) in <top (required)>'
2) Static pages About page should not have a custom page title
Failure/Error: visit '/static_pages/about'
ActionController::RoutingError:
No route matches [GET] "/static_pages/about"
# ./spec/requests/static_pages_spec.rb:57:in `block (3 levels) in <top (required)>'
3) Static pages About page should have the base title
Failure/Error: visit '/static_pages/about'
ActionController::RoutingError:
No route matches [GET] "/static_pages/about"
# ./spec/requests/static_pages_spec.rb:51:in `block (3 levels) in <top (required)>'
4) Static pages Home page should have the h1 'Sample App'
Failure/Error: visit '/static_pages/home'
ActionController::RoutingError:
No route matches [GET] "/static_pages/home"
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
5) Static pages Home page should not have a custom page title
Failure/Error: visit '/static_pages/home'
ActionController::RoutingError:
No route matches [GET] "/static_pages/home"
# ./spec/requests/static_pages_spec.rb:19:in `block (3 levels) in <top (required)>'
6) Static pages Home page should have the base title
Failure/Error: visit '/static_pages/home'
ActionController::RoutingError:
No route matches [GET] "/static_pages/home"
# ./spec/requests/static_pages_spec.rb:13:in `block (3 levels) in <top (required)>'
7) Static pages Help page should have the h1 'Help'
Failure/Error: visit '/static_pages/help'
ActionController::RoutingError:
No route matches [GET] "/static_pages/help"
# ./spec/requests/static_pages_spec.rb:27:in `block (3 levels) in <top (required)>'
8) Static pages Help page should not have a custom page title
Failure/Error: visit '/static_pages/help'
ActionController::RoutingError:
No route matches [GET] "/static_pages/help"
# ./spec/requests/static_pages_spec.rb:38:in `block (3 levels) in <top (required)>'
9) Static pages Help page should have the base title
Failure/Error: visit '/static_pages/help'
ActionController::RoutingError:
No route matches [GET] "/static_pages/help"
# ./spec/requests/static_pages_spec.rb:32:in `block (3 levels) in <top (required)>'
10) Static pages Contact page should have the h1 'Contact'
Failure/Error: visit '/static_pages/contact'
ActionController::RoutingError:
No route matches [GET] "/static_pages/contact"
# ./spec/requests/static_pages_spec.rb:65:in `block (3 levels) in <top (required)>'
11) Static pages Contact page should have the title 'Contact'
Failure/Error: visit '/static_pages/contact'
ActionController::RoutingError:
No route matches [GET] "/static_pages/contact"
# ./spec/requests/static_pages_spec.rb:70:in `block (3 levels) in <top (required)>'
Finished in 0.14305 seconds
11 examples, 11 failures
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:45 # Static pages About page should have the h1 'About Us'
rspec ./spec/requests/static_pages_spec.rb:56 # Static pages About page should not have a custom page title
rspec ./spec/requests/static_pages_spec.rb:50 # Static pages About page should have the base title
rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the h1 'Sample App'
rspec ./spec/requests/static_pages_spec.rb:18 # Static pages Home page should not have a custom page title
rspec ./spec/requests/static_pages_spec.rb:12 # Static pages Home page should have the base title
rspec ./spec/requests/static_pages_spec.rb:26 # Static pages Help page should have the h1 'Help'
rspec ./spec/requests/static_pages_spec.rb:37 # Static pages Help page should not have a custom page title
rspec ./spec/requests/static_pages_spec.rb:31 # Static pages Help page should have the base title
rspec ./spec/requests/static_pages_spec.rb:64 # Static pages Contact page should have the h1 'Contact'
rspec ./spec/requests/static_pages_spec.rb:69 # Static pages Contact page should have the title 'Contact'
答案 0 :(得分:0)
虽然您有一个根映射,它将'/'请求路由到StaticPagesController主页操作,但您没有路由static_pages/home
的映射。要添加它:
match 'static_pages/home', to: 'static_pages#home'
答案 1 :(得分:0)
在计算机上使用旧版本的Rails时,您可能正在使用Hartl书籍的Rails 4版本。试试Hartl书的Rails 3.2版本:http://ruby.railstutorial.org/chapters/filling-in-the-layout?version=3.2#sec-rails_routes