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

前端 未结 6 609
失恋的感觉
失恋的感觉 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:47

    You could try adding the following line to your environment.rb file:

    session :session_key => 'my_session_key'
    session :session_expires => 1.day.from_now
    

    Alternatively, you can set the session options as follows:

    ActionController::Base.session_options[:session_expires] = 1.day.from_now
    

    I've not tested this thouroughly, so YMMV.

提交回复
热议问题