[LRUG] Are before_filters abused in Rails?

Jay Caines-Gooby jay at gooby.org
Thu Mar 22 05:50:46 PDT 2012

On 22 March 2012 12:18, mudge <mudge at mudge.name> wrote:
> Good afternoon all,
> I posted this on Twitter a while back but seeing as the list has been
> a flurry of activity recently, I thought I'd post it here to gather
> more debate.
> Do you use before_filters in your controllers to DRY up the
> instantiation of variables like so?
> class MyController < ApplicationController
>  before_filter :load_model, :only => [:show, :edit, :update, :destroy]

resource_this https://github.com/jnewland/resource_this does exactly
this and we use it extensively. It means that you get extremely terse
controllers for basic  CRUD, and you can customise them really easily
for additional flexibility.

I also like the helper_method style

The main problem with any of these, is that in basic controllers, the
signpost of a 'helper_method :model' or 'resource_this' at the top of
the controller are easy to spot, but add in all your validation code,
relationships, etc, etc they can be easy to miss, but the DRYness of
them certainly makes it worthwhile.

Jay Caines-Gooby
jay at gooby.org
+44 (0)7956 182625
twitter, skype & aim: jaygooby
gtalk: jaygooby at gmail.com

More information about the Chat mailing list