In the following example,
before_filter :foo
before_filter :bar
before_filter :wah
prepend_before_filter :heehee
prepend_before_filter :haha
so then the execution orders will be:
haha, heehee, foo, bar, wah? <-- note that haha is actually before heehee
And is there a reason not to list haha
and heehee
first in the first place but actually use prepend
?
Before Filters ADVERTISEMENT. ADVERTISEMENT. Rails before filters are executed before the code in action controller is executed. The before filters are defined at the top of a controller class that calls them. To set it up, you need to call before_filter method.
Around filters wrap an action, executing code both before and after. They may be declared as method references, blocks, or objects responding to filter or to both before and after. To use a method as an around_filter, pass a symbol naming the Ruby method. Yield (or block. call) within the method to run the action.
To my knowledge this is to solve class inheritance where you cannot define the order of the before_filter:
ApplicationController < ActionController::Base
before_filter :do_this_first
#....
end
SomeController < ApplicationController
before_filter :do_this_second
#....
end
Here, neither of the methods defined will have preference unless you use a prepend_before_filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With