我一直在关注教程@ Noupe 的目的学习 Rails 的过程。一切进展顺利,应用程序也能运行,但我猜它是为 Rails 2 编写的,因此使用了一些已弃用的代码片段。
虽然我已经解决了大部分问题,但我还剩下一个关于路由的问题。本教程中的 Rails 2 代码为:
ActionController::Routing::Routes.draw do |map|
地图.资源:帖子
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
这工作正常,但它是旧代码。我尝试重写代码如下:
Twitter::Application.routes do
资源:帖子
匹配 ':controller/:action/:id'
匹配 ':controller/:action/:id.:format'
当我尝试访问 http://localhost:3000/posts 时,这会导致
错误 -
路由错误
没有路线匹配“/posts”
谁能建议我哪里出错了?我确实注意到,如果我在第一行(而不是 Twitter)中写入 twitter,则会出现编译器错误 - 因为我的应用程序名为 twitter,所以我认为这可能是问题所在,但似乎并非如此。
非常感谢任何帮助!
I have been following a tutorial @ Noupe with the intention of learning Rails. It's going well and the app works, but I gather it was written for Rails 2, so there are some deprecated pieces of code used.
While I have resolved most of these, I have one remaining problem with the routing. The Rails 2 code in the tutorial is:
ActionController::Routing::Routes.draw do |map|
map.resources :posts
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
This works fine, but it is the old code. I have attempted to rewrite the code as follows:
Twitter::Application.routes do
resources :posts
match ':controller/:action/:id'
match ':controller/:action/:id.:format'
end
This results in an error when I attempt to visit http://localhost:3000/posts -
Routing Error
No route matches "/posts"
Can anyone suggest where I am going wrong? I did notice that I get a compiler error if I write twitter in the first line (instead of Twitter) - since my app is named twitter, I thought this might be the issue, but it does not seem to be.
Any help greatly appreciated!
发布评论
评论(1)
您似乎错过了对绘制方法的调用。尝试将第一行更改为以下内容:
It seems like you are missing the call to the method draw. Try to change the first line to the following: