Cookies are read and written through Merb::Controller#cookies. The cookies
you read are those received in request along with those that have been set
during the current request. The cookies you write will be sent out with the
response. Cookies are read by value (so you won’t get the cookie
object itself back — just the value it holds).
Writing
cookies[:user] = "dave"
cookies[:token] = { :value => user.token, :expires => Time.now + 2.weeks }
Reading
cookies[:user]
cookies.size
Deleting
cookies.delete(:user)
Options
- value - the cookie’s value
- path - the path for which this cookie applies. Defaults to the
root
of the application.
- expires - the time at which this cookie expires, as a
Time object.
| Public Methods |
| [] |
Returns the value of the cookie by name or nil if no such cookie
exists. You set new cookies using cookies[]=
|
| []= |
Sets the value of a cookie. You can set the value directly or pass a hash
with options.
|
| delete |
Removes the cookie on the client machine by setting the value to an empty
string and setting its expiration date into the past.
|
| new |
|
<code/>and<pre/>for code samples.