How to I dynamically set the expiry time for a cookie-based session in Rails

前端 未结 6 608
失恋的感觉
失恋的感觉 2021-02-02 01:32

I\'m currently using the ActiveRecord-based session store for my Rails app and I have a background process which clears out inactive sessions every 30 minutes.

I\'d like

6条回答
  •  [愿得一人]
    2021-02-02 01:44

    After a lot of pain & experimenting, found in Rails 3.x, you need to set your custom session parameters in an after filter in every request

        class ApplicationController < ActionController::Base
    
          after_filter :short_session
    
          ...
    
          def short_session
            request.session_options = request.session_options.dup
            request.session_options[:expire_after] = 1.minute
            request.session_options.freeze
          end
    

提交回复
热议问题