Rails and REST Best Practices
Here are some of my best practices when writing RESTful Rails applications.
Rules
- Controllers should try to be as CRUDy as possible
- Non-CRUD operations in Controllers are permitted though
- Use namespaces (e.g., /admin/posts) and associations (e.g., /posts/2/comments/) to help keep controllers CRUDy
Rails 2.0 and Resources
Rails 2.0 is taking a little time to get used to. Does everything have to be a resource? Is it best practice if they are? How do I handle other GET's if the map.resource is looking for ID's as the second paramater passed to a resource (e.g., /users/login)?
All of these are questions I've been asking as I learn the latest Rails release and the benefits of REST. A lot of functionality has remained in the release, the biggest gotcha I would say are the routes. Any method you want to create needs to be mapped in the routes so that the default map.resources pattern doesn't catch it.
Page 1

