1. Skip to navigation
  2. Skip to content

The ELC Community Blog

A knowledge exchange on Ruby on Rails and Agile Development


New before_filter semantics

by Ryan Garver on November 01, 2007

It looks like Rails 2.0 will no longer pay attention to the return value of before_filters. Currently, in our Pre-Rails 2.0 world, before_filters stop processing a request when they encounter a return value of false. You may recognize the common pattern:

  redirect_to new_session_path && return false

Rails 2.0 won't require a return value of false for a before_filter to stop the action, but will instead look to see if you called redirect_to or render. If either of these functions are called the filter chain is halted. This should clean up a lot of code and remove a lot of repetition. At the end of the day your before filters look almost the same as they always have, just drop the

   1  && return false
.

Comments

David Stevenson at 9:17 PM on November 4 2007

W00t! I often forget to return true in my before filters, causing very very weird behaviour (depending on the last line… VERY weird!). Now I can just sip a iced beverage on the beach cause my debugging days are over.

Add a comment


home | services | Ruby on Rails Development | code | blog | company