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

前端 未结 6 716
失恋的感觉
失恋的感觉 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 02:01

    I stumbled across this question after a conversation in the office. Just for the sake of completeness, I've discovered that it is possible to expire sessions after a period of inactivity and it's built into Rails. In config/environment.rb, do something along the lines of:

    config.action_controller.session = {
      :key          => 'whatever',
      :secret       => 'nottellingyou',
      :expire_after => 30.minutes
    }
    

    Check out lib/action_controller/session/cookie_store.rb#114 for the (apparently undocumented) option in action. Looks like it's been around since the move to Rack sessions back in December 2008.

提交回复
热议问题