In rails for each action, is the method called in the front filter of the controller launched?

Let's say in my rails controller I have a method set_one()that is called through before_filter. Is this method called every time right before the action of the controller, or is it the one time that is executed throughout the controller? If this is one time, then this means that the instance variables that it creates will be available throughout the controller. I thought the actions of the controller are stateless. Does this help bridge the gap if it starts only once before all actions?

def set_one
 # do really complex processing and set the variable @one. 
 @one = 1;
end

Thanks in advance.:)

+4
source share
1 answer

before_filter . :

before_filter :authorize, :only => :delete

:

before_filter :authorize, :except => [:index, :show]

BTW, before_filter - before_action

+6

Source: https://habr.com/ru/post/1534577/


All Articles