ruby-on-rails - 路由错误 No route matches [GET] "/static_pages/home", tutorial

标签 ruby-on-rails ruby ruby-on-rails-3

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

Routing Error

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

Try running rake routes for more information on available routes. 

Rake 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 Controller ,它仍然响应路径 '/' 而不是 '/static_pages/home'

如果你添加

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

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

关于ruby-on-rails - 路由错误 No route matches [GET] "/static_pages/home", tutorial,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11710424/

相关文章:

ruby-on-rails - 如何从routes.rb 调用我的 Controller 操作

ruby - i18n Assets 管理/翻译 UI

ruby-on-rails-3 - Rails 形成一个模型在另一个模型 View 中的局部渲染

Ruby Date 1 个月前到 String

ruby-on-rails - Github 发现 Gemfile.lock 依赖漏洞

ruby-on-rails - Rails - 使用回形针上传 zip 文件并解压缩

ruby-on-rails - 捆绑更新然后 sprockets 抛出 filenotfound 错误 rails 3.2.3 ruby​​1.9.3p194

ruby-on-rails - Rails 关系 (has_many/belongs_to) 已完成

ruby - 从另一个数组中排除字符串数组元素

ruby-on-rails - Rails 3 run_callbacks 方法