路由错误没有路由匹配[GET]"/ static_pages/home",教程

sza*_*tan 4 ruby ruby-on-rails ruby-on-rails-3

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

Routing Error

No route matches [GET] "/static_pages/home"

Try running rake routes for more information on available routes. 
Run Code Online (Sandbox Code Playgroud)

耙路线告诉我这个:

root  /                  static_pages#home
help  /help(.:format)    static_pages#help
about  /about(.:format)   static_pages#about
contact  /contact(.:format) static_pages#contact
Run Code Online (Sandbox Code Playgroud)

我的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
Run Code Online (Sandbox Code Playgroud)

有人有个主意吗?

Ere*_*bih 8

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

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

如果你添加

match '/static_pages/home', :to =>'static_pages#home'
Run Code Online (Sandbox Code Playgroud)

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


小智 5

步骤5.3.3 Rails教程

您不必刷新页面

http://localhost:3000/static_pages/home
Run Code Online (Sandbox Code Playgroud)

但只能更改网址

http://localhost:3000/
Run Code Online (Sandbox Code Playgroud)

因为你将'static_pages/home'定义为root'/'.

对我来说它有效