Bambinos RSS

New Bamboo

Bamboo Blog

Archive

Dec
8th
Mon
permalink ismasan

Skinny controllers with resources_controller and named_scope

resources_controller takes you a long way into simplifying your controllers. Still, whenever you need to add custom collection or member routes to your app you’re out in the wild again. This snippet of code uses a combination of ActiveRecord’s named_scopes and resources_controller to simplify those custom actions. With a bit more of abtraction it could be turned into library code that you test once and reuse as many times as you want in different codebases.

The cool thing is that we get seamless nested controllers if we need them, such as in /posts or /users/2/posts