路由错误没有路由匹配[GET]“/static_pages/home",教程 [英] Routing Error No route matches [GET] "/static_pages/home", tutorial

查看:37
本文介绍了路由错误没有路由匹配[GET]“/static_pages/home",教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I run server browser show me something like this:

Routing Error

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

Try running rake routes for more information on available routes. 

Rake 路线向我展示了这个:

Rake routes shows me this:

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

我的 routes.rb 文件:

My routes.rb file:

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' 设置路由

There is no route set for the url '/static_pages/home'

尽管 root 指向 static_pages 控制器的动作 home,它仍然响应路径 '/' 而不是 '/static_pages/home'

Although root points to static_pages controller with action home, it still responds to the path '/' and not '/static_pages/home'

如果添加

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

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

You will get the expected response for '/static_pages/home'

这篇关于路由错误没有路由匹配[GET]“/static_pages/home",教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆