當我點擊一個鏈接到/index.html,我得到這個錯誤:Ruby on Rails的路由錯誤
No route matches "/index.html" with {:method=>:get}
我需要什麼,在routes.rb中添加?
當我點擊一個鏈接到/index.html,我得到這個錯誤:Ruby on Rails的路由錯誤
No route matches "/index.html" with {:method=>:get}
我需要什麼,在routes.rb中添加?
修正:
map.connect '/index.html', :controller => 'home'
在Rails通常要頁的路由資源。例如,如果你有一個項目的模式,那麼你就到/項目,這將打電話給你ProjectsController#index動作
#in config/routes.rb
resources :projects
對於像/index.html條路,我會假設你希望映射到某個主頁登陸頁面。在這種情況下,你會想要的網址爲「/」,你可以映射到控制器像
#in config/routes.rb
# This assumes you have a HomepageController with an index action and a view in app/views/homepage/index.html.erb
root :to => "homepage#index"
或者,如果你真的想「/index.htm」明明那麼你可以使用這個
# in config/routes.rb
get "/index" => "homepage#index"
許多更可以發現in the rails docs或在railscasts here
的[Ruby on Rails的路由錯誤]
可能重複(http://stackoverflow.com/questions/2245616/ruby-on-rails-routing-error) – weltraumpirat
不完全。我沒有public/index.html頁面,我使用app/views/home/index.html.erb作爲我的主頁,這是我希望/index.html重定向到的頁面。 – Michael