I have a Controller where I want to always call an after_action
before_action :auth
after_action :track, only [:index]
def index
render json: ..., status: 200
end
def show
...
end
def auth
return if some_condition
render json: ..., status 422
end
def track
status = response.status if response.successful?
# do something with status
end
What is the best way to ensure the after_action is always called? Currently it is only called if the index action is actually reached.
I've tried adding :auth to the only section of the after_action
after_action callback will only be called if the action it is attached to is executed. If you want to ensure that the track after_action is always called, regardless of which action is executed, you can use a before_action to call it at the beginning of each action