当我点击一个链接到/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