RESTful Rails
At RailsConf 2006, David Heinemeier Hansson??™s keynote marked the beginning of
the RESTful philosophy becoming mainstream in Rails. The keynote, Discovering a
World of Resources on Rails,* presented a roadmap for moving Rails 1.2 toward a
more RESTful, CRUD-based default.
* Presentation slides and video available at http://www.scribemedia.org/2006/07/09/dhh/.
210 | Chapter 7: REST, Resources, and Web Services
One of the key points in the presentation was that resources can be more than things
we might think of as ???objects???; examples given were relationships between objects,
events on objects, and object states. This is an important principle in REST. Rather
than adding another method #close on a Case object, it may be more clear to factor
out a Closure object if more information about the closure needs to be persisted.
RESTful Routing
From the outside of an application, the most visible change in RESTful Rails is the new
routing. Classic Rails routing was based around the default route of /:controller
/:action/:id, with any extra parameters usually being carried in the query string.
This had advantages of simplicity and uniformity in routing, but it was brittle to
change. Refactoring actions from one controller to another required updating all
links pointing to that action; they had to be changed from:
link_to 'Close', :controller => 'cases', :action => 'close', :id => @case.
Pages:
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330