The fetch_operator action is always executed, before every action in
every controller?
I'd want to fetch the operator only at start and not before every
action but I need to have it available on every view and controller.
The fetch_operator action is always executed, before every action in every controller?
Yes, all kind of filters implemented inside ApplicationController
class are always executed in every controller (whose parent is
ApplicationController) unless you change the behavior explicitly.
class ApplicationController < ActionController::Base
...
before_filter :fetch_operator
...
end
class anotherController < ApplicationController
before_filter :fetch_operator, :only => [:login]
end
def call_operator_once
if !session[:operator_called]
fetch_operator()
session[:operator_called] = true
end
end
Right, it will called before each action of each controller in your
application, but only one time the fetch_operator method will be
executed. I thought you want to make sure that fetch_operator method
is executed at least one time independent of controller. Now, if you
want to use a filter method and avoid to call it in other controllers
you can use "skip_before_filter :my_method" in each controller. And if
you definitely don't use this method in other controllers, I guess you
don't need define a filter method, just call it as usually in each
action that you need it, because any filter that you defined inside
the ActionController class will be inherited by other controllers.