【发布时间】:2015-05-29 12:58:50
【问题描述】:
我正在学习 Michael Hartl 的教程 Ruby on Rails 教程,并尝试完成第 3.4.4 节中的最后一步。当我将 routes.rb 更改为
Rails.application.routes.draw do
root 'static_pages#home'
get 'static_pages/help'
get 'static_pages/about'
end
然后重新启动http://localhost:3000/static_pages,他们说“我们很抱歉,但出了点问题”。然后我重新启动http://localhost:3000/static_pages/help,它就可以工作了。然后我通过
检查路线rake routes
结果显示:
Prefix Verb URI Pattern Controller#Action
root GET / static_pages#home
static_pages_help GET /static_pages/help(.:format) static_pages#help
static_pages_about GET /static_pages/about(.:format) static_pages#about
我检查了文件 static_pages_controller.rb 中的内容,与教程中的内容没有区别。谁能告诉我怎么了?
【问题讨论】:
-
你不是倒退了吗?您的路由定义是否意味着如果您访问
http://localhost:3000/,它将调用控制器static_pages上的操作home?您要映射什么 URL(以及映射到什么控制器/操作)? -
解决了这个问题。请原谅我是网络开发的新手。
标签: ruby-on-rails