Webservices are nice and all, but it's not the reason why I use map.resources. In fact most of the time I will not implement webservices at all except for where I need them, since this is additional code that might break and will probably be untested. Besides all those respond_to blocks make controllers a pain to read.
The term REST has in the Rails world become almost synonymous with map.resources, but it's not, really. REST are web services, map.resources is just a different way of organizing your controller, and to me it makes perfect sense, so let me explain:
- you know where everything goes Before REST came I (and pretty much everyone else) never really knew where to put stuff. Say you have a Post model and a Comment model, for comments there will only be add and delete, not the full set of CRUD operations. Now you're unsure, do I create two seperate controllers for this or do I create just one? With map.resources the answer is obvious, two models = two controllers. Without map.resources everyone stuck to their personal preference, which ended up becoming a horrible mess when collaborating with other people. Now this is just one example, there are other such organizational things in controllers that are made way easier by map.resources.
- all that hassle with GET and POST and GWR is finally gone. Always needing to protect your methods from destructive GET requests was a pain, and it was inelegant. Say you would have something like 'verify :method => :post, :redirect => blah' in your controller, now that is just ugly. No such hassle with map.resources.
- No leeky URLs Honestly, having a /person/create URL is stupid, and granted it was possible to have /person/new be both form and post method, but that led to some seriously ugly controller code.
- Prettier URLs oh yes, they are prettier /person/1 tops /person/show/1 by miles imho, and person/jncoward is waaay better than person/show/jncoward, no?
- Ability to selectively 'turn off' controllers. Need to disable a feature for a while? No problem, just comment out the map.resources in your routes file and it's dead and gone.
- Named routes mean none of that stupid curly bracket nonsense Need to set the class for a link? So what looks better?
link_to @user.name, { :controller => 'person', :action => 'show', :id => @user }, { :class => 'delete' }
or
link_to @user.name, user_path(@user), :class => 'delete'
hey or even:
link_to @user.name, @user, :class => 'delete'
There are probably some further reasons, this is what I came up with
off the top of my head. So give map.resources a spin, you'll very
probably like it
/Jonas