Module: Fastr::Cookie
- Included in:
- Controller
- Defined in:
- lib/fastr/cookie.rb
Overview
This module adds helpers for handling cookies.
Setting a cookie
("mycookie", "value", {:expires => Time.now + 3600})
Instance Method Summary collapse
-
#set_cookie(key, value, options = {}) ⇒ Object
Adds a Set-Cookie header in the response.
Instance Method Details
#set_cookie(key, value, options = {}) ⇒ Object
Adds a Set-Cookie header in the response.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fastr/cookie.rb', line 15 def (key, value, ={}) = ["#{key}=#{value};"] if .has_key? :expires and [:expires].kind_of? Time [:expires] = [:expires].utc.strftime('%a, %d-%b-%Y %H:%M:%S GMT') end # Sort the cookies alphabetically. .sort { |a,b| a.to_s <=> b.to_s }.each do |k,v| << "#{k}=#{v.to_s};" end = .join(' ') if self.headers['Set-Cookie'].nil? self.headers['Set-Cookie'] = [] else self.headers['Set-Cookie'] << end end |