1

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?

Andrew
  • 42,517
  • 51
  • 181
  • 281
shishirmk
  • 425
  • 2
  • 14

1 Answers1

1

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

Chris Schmitz
  • 8,097
  • 6
  • 31
  • 41
  • Thanks for solving the confusion. However is there anyway to execute a method after bar is rendered? – shishirmk Apr 22 '12 at 23:22
  • This looks like it might be helpful, even though it's for an older version of Rails: http://stackoverflow.com/questions/4325538/rails-2-3-x-execute-code-after-request-was-rendered-and-returned – Chris Schmitz Apr 23 '12 at 00:50