Here’s one that could have you scratching your head in puzzlement for a little while. In Rails 1.2.x you could do something like this in your controller:
class PostsController < ActionController::Base
before_filter :do_filter
# Controller code
protected
def do_filter
# Filter logic goes here
# Halt the filter chain
false
end
end
If the filter returned false then processing of the request would stop and you’d see a blank page in your browser.
Not so in Rails 2.0: thanks to changeset 7984 the filter chain is only halted if you render or redirect within your filter. If you really want to get similar behaviour to Rails 1.2.x you could always do this:
def do_filter
# Filter logic goes here
# Halt the filter chain
head :bad_request
end
Although you will probably be more popular with your users if you display some kind of friendly error message!


1 comment
Comment on Halting the filter chain in Rails 2.0 by Sachin
October 4th, 2008 @ 08:25 – permalink
Leave a reply
You can use Markdown in your comment as well as plain HTML. You can use
<filter:jscode lang="ruby">and</filter:jscode>tags to surround code blocks (supported languages are css, html, javascript and ruby). Your email address will not be published.If your comment doesn’t appear immediately after posting it could have been marked as spam. Don’t worry: we regularly check for and approve incorrectly filtered comments so you shouldn’t have to wait too long for it to be shown.