Take the most simple example:
map.resource:account
1) How different is it from defining all the names routes – like:
:map.new_account “new_account”, :controller=>”activity”, :action=>”new”
2) How do you set an additional route within the resource definition? For example, say there is one more method for the resource
:map.brand_new_action “brand_new_action”, :controller=>”activity”, :action=>”brand_new_action”
Do we just add it below? But that seems to defeat the point of the resource
How different is it from defining all the routes manually?
It’s not different, in that it’s more of a convenience. Why would you want to define all your routes by hand, that can be quite tedious. So the common CRUD actions are mapped automatically, below is an example using a contacts controller:
These are commonly referred to as the “7 Restful Actions,” however you can add your own custom routes if needed (although you’re strongly encouraged to use the 7 whenever possible).
How do you add additional resources/routes?
Adding additional routes is easy. First you want to decide if you’re working with a collection or a specific member, then also consider if the action is creating or updating something. For update actions you want to use PUT, create POST, destroying uses DELETE, and anything else is probably a GET.
Most of the time the 7 Restful Actions are plenty enough, but in some situations you’ll need custom routes. This is why Rails handles the most common case and gives you the ability to handle unique cases.