我剛剛使用Hartl的教程也遇到同樣的問題。這是我做的。
當問rake routes
,我有:
tomsihap-MBP:sample_app tomsihap$ rake routes
Prefix Verb URI Pattern Controller#Action
root GET/ static_pages#home
static_pages_help GET /static_pages/help(.:format) static_pages#help
static_pages_about GET /static_pages/about(.:format) static_pages#about
static_pages_contact GET /static_pages/contact(.:format) static_pages#contact
然後正確的路徑是:
<%= link_to "About", static_pages_about_path %>
而且不<%= link_to "About", about_path %>
通過哈特爾指南的建議。
編輯:
好吧,現在我明白了。這是因爲線路被定義這樣的:
Rails.application.routes.draw do
root 'static_pages#home'
get 'static_pages/help'
get 'static_pages/about'
get 'static_pages/contact'
相反的,後來解釋到教程:
Rails.application.routes.draw do
root 'static_pages#home'
get 'help' => 'static_pages#help'
get 'about' => 'static_pages#about'
get 'contact' => 'static_pages#contact'
使用這種方式,正確的路徑現在是:
<%= link_to "About", about_path %>
@約翰Topley。感謝您修復這些錯別字 – bjg 2010-07-28 11:52:22