路由错误没有路由匹配“/ static_pages / home”,教程

当我运行服务器浏览器时显示如下:

Routing Error No route matches [GET] "/static_pages/home" Try running rake routes for more information on available routes. 

耙路线告诉我这个:

 root / static_pages#home help /help(.:format) static_pages#help about /about(.:format) static_pages#about contact /contact(.:format) static_pages#contact 

我的routes.rb文件:

 MyApp::Application.routes.draw do root :to => 'static_pages#home' match '/help', :to => 'static_pages#help' match '/about', :to => 'static_pages#about' match '/contact', :to =>'static_pages#contact' end 

有人有个主意吗?

url’/ static_pages / home’没有路由集

虽然root指向带有action home的static_pages控制器,但它仍然响应路径’/’而不是’/ static_pages / home’

如果你添加

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

您将获得’/ static_pages / home’的预期响应

步骤5.3.3 Rails教程

您不必刷新页面

 http://localhost:3000/static_pages/home 

但只能更改URL

 http://localhost:3000/ 

因为你将’static_pages / home’定义为root’/’。

对我来说它有效

当我遵循Ruby on Rails教程时,我得到了与szatan相同的错误。 该错误是因为,之前我们测试的URL是http://localhost:3000/static_pages/help因为操作是在static_pages中。 但是,在改变routes.rb之后

 get 'static_pages/help' to match '/help', to: 'static_pages#help 

URL应更改为http://localhost:3000/help因为我们告诉Rails服务器将路径/help路由到static_pages#help 。 我们不应指望用户知道路径/static_pages/help

请记住删除“public / index.html”文件。

您可以正确定义所有路由,但如果保留此文件,则不会正确路由它。

您可以指向"/"root_path而不是'/static_pages/home' 。 无需将两条路线指向同一个地方……

你应该添加:作为定义XXX_path的keword,例如root:to =>’static_pages #home’

 match '/', to: 'static_pages#home', :as => :home match '/help', to: 'static_pages#help', :as => :help match '/about', to: 'static_pages#about', :as => :about match '/contact', to: 'static_pages#contact', :as => :contact 

当我到达教程中的这一点时,我遇到了这个问题。 当我将浏览器指向"http://localhost:3000/"并重新加载时,它已得到解决。