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.
Hope you enjoy it!
Disclaimer: this video is long, around 50 min long. I first recorded it, live, in english and I tried to do voice over it in portuguese. But it was so difficult that I decided to record again another version in portuguese. This second video ended up being having a different concept and I explain Restful Rails in a bit more detail because the Brazilian audience can’t understand english well enough to learn through Peepcode. So, if you can understand portuguese, you will want to check it out as well.