Forum: Ruby on Rails CookieStore and setting an expiration

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0413d624aece24d1dc7215226136bdc4?d=identicon&s=25 etienne (Guest)
on 2009-05-01 19:08
(Received via mailing list)
hi everyone,

i can't seem to find any help online for this.  I'm using
CookieStore.  What I can't seem to figure out how to do is set the
expiration for the cookie set by CookieStore.  Right now it leaves
that field blank, meaning that the  cookie expires when the browser is
closed.  The context is for a login, where the user has the option to
check a "leave me logged in" option that would expire the cookie 2
weeks or 3 weeks later.

thanks,
etienne
Ced56202e9039027cfc2da2f70457977?d=identicon&s=25 E. Litwin (Guest)
on 2009-05-01 19:18
(Received via mailing list)
cookies[:key] = {:value => value, :expires => 3.weeks.from_now}
0413d624aece24d1dc7215226136bdc4?d=identicon&s=25 etienne (Guest)
on 2009-05-03 18:12
(Received via mailing list)
That overwrites the cookie for the session.  By the time they attempt
to login, a session has already begun for them.  CookieStore is doing
the management behind the scenes.  I want to amend the cookie to have
an expiration date which, it seems, it does not have by default.
etienne
407016c9d4109e726fc30681b21324cc?d=identicon&s=25 Jarl Friis (jarl)
on 2009-05-05 15:23
(Received via mailing list)
etienne <pelaprat@gmail.com> writes:

> That overwrites the cookie for the session.  By the time they attempt
> to login, a session has already begun for them.  CookieStore is doing
> the management behind the scenes.  I want to amend the cookie to have
> an expiration date which, it seems, it does not have by default.
> etienne

Try this in your config/environment.rb

  config.action_controller.session = {
    :session_key => '_yourapp',
    :secret      => 'yoursecret',
    :expire_after => 600 # seconds
  }

It works for me.

Jarl
This topic is locked and can not be replied to.