title: Devise redirect after login or logout doesn't work with Rails page caching
body: <p>I'm using Devise for authentication in my Rails app on Heroku.</p>
  
  <p>I have redirects after login and logout setup the way it's suggested to do so in the Devise wiki. (<a href="https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update" rel="nofollow">https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update</a>)</p>
  
  <p>application_controller.rb:</p>
  
  <pre><code>after_filter :store_location
  
  def store_location
    # store last url as long as it isn't a /users path
    session[:previous_url] = request.fullpath unless (request.fullpath =~ /\/users\/sign_in/ || request.fullpath =~ /\/users\/sign_out/ || request.fullpath =~ /\/users\/sign_up/ || request.fullpath =~ /\/users\/edit/ || request.fullpath =~ /\/ajax_utilities/ || request.fullpath =~ /\/assets/)
  end
  
  def after_sign_in_path_for(resource)
    session[:previous_url] || root_path
  end
  
  def after_sign_out_path_for(resource)
    session[:previous_url] || root_path
  end
  </code></pre>
  
  <p>The redirects work fine until I enable page caching with code like this:</p>
  
  <pre><code>class AboutController &lt; ApplicationController
  
    def index
        expires_in 1.minutes, public: true
    end
  
  end
  </code></pre>
  
  <p>I'm 99% sure that store_location isn't ever being called because the way page caching works in Rails the application controller would never even be reached because Rack serves the static HTTP without touching Rails.</p>
  
  <p>Does anyone have any ideas about how I can take advantage of Rails page caching while also having my redirects after login/logout work correctly for Devise?</p>
  
  <p>Thanks for any help.</p>