class ActionDispatch::Cookies
only HTTP. Defaults to false
.
* :httponly
- Whether this cookie is accessible via scripting or
Default is false
.
* :secure
- Whether this cookie is a only transmitted to HTTPS servers.
* :expires
- The time at which this cookie expires, as a Time object.
domain and subdomains.
:domain => :all # Allow the cookie for the top most level
:domain => nil # Does not sets cookie domain. (default):all
again when deleting keys.
to :all
. Make sure to specify the :domain
option with
and want to share session with user.example.com set :domain
restrict to the domain level. If you use a schema like www.example.com<br>* :domain
- The domain for which this cookie applies so you can
of the application.
* :path
- The path for which this cookie applies. Defaults to the root
* :value
- The cookie’s value or list of values (as an array).
The option symbols for setting cookies are:
cookies.delete(:key, :domain => ‘domain.com’)
}
:domain => ‘domain.com’
:expires => 1.year.from_now,
:value => ‘a yummy cookie’,<br>cookies = {
Please note that if you specify a :domain when setting a cookie, you must also specify the domain when deleting the cookie:
cookies.delete :user_name
Example for deleting:
cookies.size # => 2<br>cookies # => “david”
Examples for reading:<br><br>cookies.permanent.signed = “XJ-122”
# You can also chain these methods:<br>cookies.permanent = “XJ-122”
# Sets a “permanent” cookie (which expires in 20 years from now).<br><br>cookies.signed = [current_user.id, current_user.salt]
# You must specify a value in ActionController::Base.cookie_verifier_secret.
# Sets a signed cookie, which prevents a user from tampering with its value.<br><br>cookies = { :value => “XJ-122”, :expires => 1.hour.from_now }
# Sets a cookie that expires in 1 hour.<br><br>cookies = “david”
# Sets a simple session cookie.
Examples for writing:
the cookie object itself back, just the value it holds.
being written will be sent out with the response. Reading a cookie does not get
The cookies being read are the ones received along with the request, the cookies
Cookies are read and written through ActionController#cookies.
def call(env)
def call(env) status, headers, body = @app.call(env) if cookie_jar = env['action_dispatch.cookies'] cookie_jar.write(headers) if headers[HTTP_HEADER].respond_to?(:join) headers[HTTP_HEADER] = headers[HTTP_HEADER].join("\n") end end [status, headers, body] end
def initialize(app)
def initialize(app) @app = app end