2011-06-09 69 views
0

我一直在有這個問題了,而有一個主頁,我似乎無法繞到我的大腦,我已經重新一切從頭開始了無數次邁克爾·哈特爾指南第5章LayoutLinks應在「/」問題

無論如何,我在這本書的一部分,我們希望主頁鏈接從http://localhost:3000/pages/home(這工作完美順便)到http://localhost:3000 (基本上意思是我希望主頁顯示在根頁面上)

目前我的錯誤是 LayoutLinks應該有一個主頁'/' 失敗/錯誤:response.should have_選擇器('標題',:內容=>「首頁」) 它下面是一堆文字說這個頁面應該看起來像。

現在我做了兩件事情,我第一次創建layout_links_spec.rb頁面,添加了幫助頁面的pages_controller.rb,並添加路由配置低於/ 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

將「end」添加到routes.rb的末尾:) 有一個塊,用「do」打開,但沒有關閉它。仔細檢查清單5.20。

+0

它在那裏我只是忘了添加它 – matt 2011-06-09 02:34:36

+0

你看到根頁/如果你手動檢查它? – 2011-06-09 02:42:14

+0

你是什麼意思手動檢查它?你是說如果我喜歡/家? – matt 2011-06-09 02:54:38

相關問題