Set Rack session cookie expiration programmatically

I was trying to do the exact same thing and I figured out what the problem for me was. The session cookie gets set on every request if you have an expire_after time set. So when you say if (!remember_me), for that request the cookie's expire time gets set to nil. However, on the very next request, the session cookie is reinitialized with an expire time of 2592000. It seems the fix is to not set a default expire_after time and instead say:

# don't set default expire time
use Rack::Session::Cookie, :secret => MY_SECRET


if(remember_me) 
  env['rack.session.options'][:expire_after] = 2592000 
end

I have unfortunately not figured out how to have a default expire_after time and to permanently extend that time programatically.