2011-08-11 70 views
0

我folllowed此: http://ruby.railstutorial.org/chapters/filling-in-the-layout#sec:user_signupRails項目,「路由錯誤沒有路由匹配」/頁「」需要幫助

但是,當我嘗試訪問http://localhost:3000/pages/返回「路由錯誤的路由匹配‘/頁’」

這是我的routes.rb

Sample4App::Application.routes.draw do 

    get "users/new" 

    match '/signup', :to => 'users#new' 

    match '/contact', :to => 'pages#contact' 
    match '/about', :to => 'pages#about' 
    match '/help', :to => 'pages#help' 

    match '/', :to => 'pages#home' 
end 

這是我home.html.erb

<h1>Sample App</h1> 

<p> 
    This is the home page for the 
    <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> 
    sample application. 
</p> 

<%= link_to "Sign up now!", signup_path, :class => "signup_button round" %> 

我盡力了。但仍然。 真的需要幫助。謝謝

回答

2

這似乎是你錯過了'/頁/'的實際路線。根

root :to => 'pages#home' 

所以你可以添加以下到您的routes.rb

match '/pages' => 'pages#home' 
+0

謝謝,但不行。實際上,根(/')是東西'網頁#家' –

+2

好吧,我只是假設你想/頁面被路由到家裏,因爲你沒有指定。但如果這是不正確的,那麼當你瀏覽/頁面時你想要發生什麼? – DanneManne

+0

@Josh Morrison,這是你想要的。 @DanneManne,'搭配'更好用'get'取代 – fl00r

0

添加這一點,你可以訪問http://localhost:3000

或添加

match '/pages', :to => 'pages#home' 

這樣你就可以訪問http://localhost:3000/pages

+0

不對。非常感謝。 –

+0

用耙路線檢查我認爲匹配'/',:to =>'pages#home'會給URL http:// localhost:3000而不是http:// localhost:3000/pages –

0

試試這個:

Sample4App::Application.routes.draw do 
    get "users/new" 

    match 'signup' => 'users#new' 

    match 'contact' => 'pages#contact' 
    match 'about' => 'pages#about' 
    match 'help' => 'pages#help' 

    match 'pages' => 'pages#home' 

    root :to => 'pages#index' 
end 

並確保你在你的Pages控制器index行動。

0

試試這個

root :to => 'pages#index' 

像其他人前面說的,但是你從/公/文件夾中刪除index.html.erb?刪除它,然後再試一次 - 這應該可以解決問題:)

相關問題