Before_filter does not cancel the action

I'm having problems getting filters to work in a Rails application. I recently updated it from 1.9 (?) To 2.3.11. To try and debug it, I put before_filter before the controller:

before_filter :false_filter 

and in application application_controller.rb:

 def false_filter puts "false filter running" false end 

Then I call the method either from cucumber / webrat or from the browser, and when the filter receives the call (I see that puts displays a message), the filter chain does not end.

I am wondering if there is some kind of boilerplate code that has not been generated. Can anyone suggest where to look?

+44
ruby-on-rails
Jun 15 '11 at 5:10
source share
1 answer

Nothing pays attention to the return value before the filter. If you want to stop processing, you should do something from your filter or redirect to another place, from a thin guide :

If it is displayed or redirected before the filter, the action will not be performed. If after this filter additional filters are run, they will also be canceled.

The same text is displayed in the 2.3.8 guide .

This behavior makes sense if the filter chain is not completed (i.e. it stops filtering part of the path), then you end up calling the controller methods with things that are not configured as they expected, and this will just cause pain, suffering and confusion, and that would not be friendly or funny at all.

+88
Jun 15 2018-11-11T00:
source share



All Articles