我已经有一段时间没有这个问题了,因为我已经无数次地从头开始重新创建所有东西,所以我似乎无法包裹我的大脑
无论如何,我在本书的一部分,我们希望主页链接从http://localhost:3000/pages/home(顺便说一句,工作顺利)到http://localhost:3000 (基本上我的意思是我希望主页显示在根页面上)
目前我遇到的错误是 LayoutLinks的主页应该是'/' 失败/错误:response.should have_selector('title',:content =>“Home”) 在它下面是一堆文字,说该页面应该是这样的。
现在我做了两件事,我首先创建了layout_links_spec.rb页面,将帮助页面添加到pages_controller.rb,并将路由添加到config / routes.rb下面是所有3的代码
layout_links_spec.rb
require 'spec_helper'
describe "LayoutLinks" do
# describe "GET /layout_links" do
# it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
# get layout_links_index_path
# response.status.should be(200)
it "should have a Home page at '/'" do
get '/'
response.should have_selector('title', :content => "Home")
end
it "should have a Contact page at '/contact'" do
get '/about'
response.should have_selector('title', :content => "About")
end
it "should have a Help page '/help'" do
get '/help'
response.should have_selector('title', :content => "Help")
end
end
Pages_controller.rb
def home
@title = "Home"
end
def contact
@title = "Contact"
end
def about
@title = "About"
end
def help
@title = "Help"
end
end
配置/ routes.rb中
SampleApp::Application.routes.draw do
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
root :to => 'pages#home'
end
我做错了吗?
答案 0 :(得分:0)
将“end”添加到routes.rb :)的末尾 有一个块,以“do”打开,你没有关闭它。仔细检查清单5.20。