shishirmk
shishirmk

Reputation: 425

after_filter :foo foo runs before controller in rails 3.2

I must be doing something wrong here. I want to a function to run after the controller has run. This function populates some part of my session variable and then i use that information in the next request. Here is the code.

class SummariesController < ApplicationController  
    after_filter :foo, :only=>[:bar]  

    def foo  
        session[:x] = y  
    end  

    def bar  
        #some code  
    end  
end  

In this code foo gets called before bar. I want it to be called after bar is rendered. What am i doing wrong?

Upvotes: 1

Views: 783

Answers (1)

Chris Schmitz
Chris Schmitz

Reputation: 8247

after_filter executes before the response is sent to the client, so you wouldn't be able to run this after bar is rendered. From the Rails Guides:

they have access to the response data that’s about to be sent to the client

Upvotes: 1

Related Questions