2

I have following line in my application which let default cookie expire date 20 minutes.

Rails.application.config.session_store :cookie_store, key: '_rails-omniauth_session', expire_after: 20.minutes

Bu I want to set specific expire date for some reasons. I have tried following lines but they couldn't make it.

request.session_options[:expire_after] = 2.years
ActionController::Base.session_options[:expire_after] = 2.years

How can set custom expire date ?

Ang suggestions,

Thanks.

Hilmi Yamcı
  • 463
  • 8
  • 20

1 Answers1

1

If you need to set expiration period for sessions through all controllers in your application, simply add the following option to your config/intializers/session_store.rb file:

:expire_after => 60.minutes

If you need to set different expiration time in different controllers or actions, use the following code in action or some before_filter:

request.session_options = request.session_options.dup
request.session_options[:expire_after] = 5.minutes
request.session_options.freeze

Duplication of the hash is needed only because it is already frozen at that point

Source

Chloe
  • 25,162
  • 40
  • 190
  • 357
Radix
  • 2,527
  • 1
  • 19
  • 43