I have been having this issue for a while now and I cannot seem to wrap my brain around as I have recreated everything from scratch numerous times
Anyways I 开发者_Python百科am at the part of the book where we want the home page link to go from http://localhost:3000/pages/home (This worked perfectly by the way) to http://localhost:3000 (basically meaning I want the home page to show up on the root page)
Currently the error i have is LayoutLinks should have a Home page at '/' Failure/Error: response.should have_selector('title', :content => "Home") And underneath it is a bunch of text saying waht the page should look like.
Now I did 2 things, I first created the layout_links_spec.rb page, added the help page to the pages_controller.rb, and added the routes to config/routes.rb below is the code for all 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
config/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
Is there something I am doing wrong?
Add "end" to the end of your routes.rb :) There is a block, that opens with "do" and you didn't close it. Check the listing 5.20 carefully.
精彩评论