[LRUG] Are before_filters abused in Rails?

Jamie Cobbett jamiecobbett85 at gmail.com
Thu Mar 22 05:36:51 PDT 2012

Yep we use it everywhere, I can't see a problem with it. 

On 22 Mar 2012, at 12:31, Richard Taylor <richard at richt.co.uk> wrote:

> I can see where they are coming from in the purist sense, but I find this pattern extremely useful and adopt it widely.  Until someone can come up with a better DRY example I'll be sticking to this.
> -- 
> Richard Taylor
> On Thursday, 22 March 2012 at 12:18, mudge 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]
>> def show
>> end
>> def edit
>> end
>> private
>> def load_model
>> @model = Model.find(params[:id])
>> end
>> end
>> It's a pattern that I've seen quite a bit and something we had taken
>> to using until a member of the team began challenging it during code
>> review. The gist of the issue is that he believed it to be an abuse of
>> filters which should really only deal with things like authentication;
>> it was his assertion that the actual loading of a model should be made
>> much more explicit.
>> The full discussion can be found at https://gist.github.com/2007669
>> and I've added a few alternatives (including one inspired by the
>> latest Ruby Rogues discussion about Objects in Rails
>> http://rubyrogues.com/046-rr-objects-in-rails-part-2/) but I'd be keen
>> to see what people here think and whether it is an issue or not.
>> _______________________________________________
>> Chat mailing list
>> Chat at lists.lrug.org
>> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20120322/ce03cd32/attachment-0003.html>

More information about the Chat mailing list