Easy Restful Rails

Posted in Development, Frameworks, Databases, Web Technologies on February 27, 2008


Easy Restful Rails

So, the idea came when I saw James Golick’s excelent resource_controller plugin. It does what I always thought should be part of Rails itself: it made Restful Controller as easy to use and understand as ActiveRecord originally does for Models and the database.

This screencast is a quick rendition to this plugin and how to use to leverage the power of Restful controller in your applications. This is one of those great ideas that – who knows – could find its place in the Rails Core one day, the same way Sexy Migrations did.

The concept is that now that we treat a controller’s action in a standardized way (through the abstraction of HTTP verbs) it could perfectly be refactored away from the day-to-day development. So, instead of scaffold creating a bunch of repeated code in every controller, why not have a bare-bone controller, totally empty, to start with?

Another clever idea was to create dynamic helpers for named routes in the views. That way you can move your views around, and even reuse them in different sections without ever copying & pasting several different named routes between them. This is particularly useful for polymorphic controllers and namespaced routes as I show in this video.

At the very end of the video I do a quick summary of what Restful Rails provides you in terms of routes organization, that could be helpful to some.

Watch Video

Tags: Ruby, Ruby On Rails, Frameworks, Databases, REST