[英]Ruby on Rails routes.rb
This question has probably been answered multiple times but I am trying to understand the concept and since I am completely new to Ruby on Rails I am hoping someone can explain it to me. 这个问题可能已经被回答了多次,但是我试图理解这个概念,并且由于我是Ruby on Rails的新手,所以我希望有人可以向我解释一下。
I'm following a tutorial to create a small twitter post app and its asked me to put the following in the route.rb file and run WEBrick to see if its working. 我正在按照一个教程创建一个小的Twitter帖子应用程序,它要求我将以下内容放入route.rb文件中,然后运行WEBrick看看其是否有效。
ActionController::Routing::Routes.draw do |map|
map.resources :posts
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
The problem with that is as soon as I run "rails server" the server starts and after a few seconds exits and give this 问题是,一旦我运行“ rails服务器”,服务器就会启动,并在几秒钟后退出并给出
..RubyProjects/twitter/config/routes.rb:57:in `block in ': uninitialized constant ActionDispatch::Routing::Routes (NameError)...
..RubyProjects / twitter / config / routes.rb:57:in'block in':未初始化的常量ActionDispatch :: Routing :: Routes(NameError)...
a lot of other errors but I suspect they are all being created by the one above. 还有很多其他错误,但我怀疑它们都是由上述错误创建的。 I am running Ruby 1.9.3p429 and Rails 4.0.0.rc2.
我正在运行Ruby 1.9.3p429和Rails 4.0.0.rc2。
Whiel I was searching for a solution i did realize that this might be caused because I am using syntax from an earlier version which has changed in Rails 4 but I cannot figure out what the correct syntax would be for the new version. 在寻找解决方案时,我确实意识到这可能是由于我使用的是Rails 4中已更改的早期版本中的语法而导致的,但是我无法弄清楚新版本的正确语法是什么。
What would the syntax be for a newer version be in this instance? 在这种情况下,较新版本的语法是什么?
Do it like this:- 像这样做:-
<yourprojectname>::Application.routes.draw do
resources :products
match ':controller(/:action(/:id))(.:format)'
end
get ':controller(/:action(/:id(.:format)))'
将此优先级最低的行(最后一行)写入config/routes.rb
文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.