[LRUG] Are before_filters abused in Rails?

Elise Huard lrug at elisehuard.be
Thu Mar 22 06:27:32 PDT 2012


I've been on one project where before_filters and around_filters were
abused, where basically everything happened in the before filters -
breadcrumb magic, non-standard actions ...
in that case it became a bit of an antipattern, because you had to
start looking all over to place to see what a particular controller
action was doing.
But if used with care and clarity, they're pretty useful.

On 22 March 2012 12:50, Jay Caines-Gooby <jay at gooby.org> 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.
>
> --
> Jay Caines-Gooby
> http://jay.gooby.org
> jay at gooby.org
> +44 (0)7956 182625
> twitter, skype & aim: jaygooby
> gtalk: jaygooby at gmail.com
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org



More information about the Chat mailing list