Skip to content

Instantly share code, notes, and snippets.

@gmarik
Created April 4, 2011 22:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmarik/902573 to your computer and use it in GitHub Desktop.
Save gmarik/902573 to your computer and use it in GitHub Desktop.
:expire_after rails 2.3.11 workaround
# workaround for https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6634-railsrack-inconsistency-about-expires_afterexpires-cookie-option#ticket-6634-3
# expiration issue
# drop into RAILS_ROOT/config/initializers/expires_fix_2311.rb
#
require 'rack'
Rack::Utils.class_eval do
class << self
def set_cookie_with_expire!(header, key, value)
if value[:expires].blank? && value[:expire_after]
value[:expires] = Time.now + value[:expire_after]
end
set_cookie_without_expire!(header, key, value)
end
alias :set_cookie_without_expire! :set_cookie_header!
alias :set_cookie_header! :set_cookie_with_expire!
end
end
@agibralter
Copy link

Super useful -- thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment