0

I'm using Devise for authentication in my Rails app on Heroku.

I have redirects after login and logout setup the way it's suggested to do so in the Devise wiki. (https://github.com/plataformatec/devise/wiki/How-To:-Redirect-back-to-current-page-after-sign-in,-sign-out,-sign-up,-update)

application_controller.rb:

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

The redirects work fine until I enable page caching with code like this:

class AboutController < ApplicationController

  def index
      expires_in 1.minutes, public: true
  end

end

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.

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?

Thanks for any help.

4

1 回答 1

0

AboutController

before_filter :destroy_cache

def destroy_cache
  response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
  response.headers["Pragma"] = "no-cache"
  response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end

不确定它到底是你需要的,但也许是一个起点

看看这篇文章和原始引用

更新:

看看这篇文章。它将向您展示如何设置友好转发,这听起来像您想要做的

于 2013-05-15T19:49:11.997 回答