In Ruby on Rails, does map.resources: Stories immediately make Story RESTful?
I read Simply Rails by Patrick Lenz ... maybe I missed something, it seems that whenever we put
map.resources :stories
in routes.rb
then immediately the controller will have a special convention and now the Story is a RESTful resource? Maybe the author used a word resource but didn't mention that it is RESTful but are they the same thing?
a source to share
Having routes in it means you automatically get a few standard routes to help you create a relaxed app. For instance:
new_story GET /story/new(.:format) {:action=>"new", :controller=>"stories"}
edit_story GET /story/edit(.:format) {:action=>"edit", :controller=>"stories"}
story GET /story(.:format) {:action=>"show", :controller=>"stories"}
PUT /story(.:format) {:action=>"update", :controller=>"stories"}
DELETE /story(.:format) {:action=>"destroy", :controller=>"stories"}
POST /story(.:format) {:action=>"create", :controller=>"stories"}
By simply having this one line in your routes file, you can use all of these paths. You just need to make sure you provide the correct functionality in new ones, edit, show, update, destroy and create your story controller actions, and you have a calm design.
To see what's available along the route, you can go to your application folder and issue the command:
rake routes
This lists all the paths available to you, based on what you entered in your routes file.
a source to share
BUT!!! If you have other actions in the controller, they will NOT be found unless you enter additional routes ABOVE that .resources line!
So, if you have an action called turn_page in your story controller, you need to include the map.connect line before the map.resources line - like in this snippet:
map.connect 'stories/turn_page', :controller => 'stories', :action => 'turn_page'
map.resources :stories
Hope someone can help! I got stuck for a few hours working on this since all examples are "regular" routes or a REST set defined via the .resources statement!