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.
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.
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
..RubyProjects/twitter/config/routes.rb:57:in `block in ': uninitialized constant 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.
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.
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
文件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.