[LRUG] Are before_filters abused in Rails?

Ash Berlin ash_lrug at firemirror.com
Fri Mar 23 03:26:07 PDT 2012

On 22 Mar 2012, at 12:50, Jay Caines-Gooby wrote:

> 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
> https://gist.github.com/2007669#file_helper_method_controller.rb
> 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.

inherited_resources does both of these automatically (s/model/resource/ for the helper method) - http://github.com/josevalim/inherited_resources/

After having a quick glance at resource_this inherited_resources seems to largely similar but might be easier to override behaviour on one action (though I only glanced at the docs for r_t quickly)


More information about the Chat mailing list