Parent

Methods

Class Index [+]

Quicksearch

ActionDispatch::Cookies

Cookies are read and written through ActionController#cookies.

The cookies being read are the ones received along with the request, the cookies being written will be sent out with the response. Reading a cookie does not get the cookie object itself back, just the value it holds.

Examples for writing:

  # Sets a simple session cookie.
  cookies[:user_name] = "david"

  # Sets a cookie that expires in 1 hour.
  cookies[:login] = { :value => "XJ-122", :expires => 1.hour.from_now }

  # Sets a signed cookie, which prevents a user from tampering with its value.
  # You must specify a value in ActionController::Base.cookie_verifier_secret.
  cookies.signed[:remember_me] = [current_user.id, current_user.salt]

  # Sets a "permanent" cookie (which expires in 20 years from now).
  cookies.permanent[:login] = "XJ-122"
  # You can also chain these methods:
  cookies.permanent.signed[:login] = "XJ-122"

Examples for reading:

  cookies[:user_name] # => "david"
  cookies.size        # => 2

Example for deleting:

  cookies.delete :user_name

Please note that if you specify a :domain when setting a cookie, you must also specify the domain when deleting the cookie:

 cookies[:key] = {
   :value => 'a yummy cookie',
   :expires => 1.year.from_now,
   :domain => 'domain.com'
 }

 cookies.delete(:key, :domain => 'domain.com')

The option symbols for setting cookies are:

Constants

HTTP_HEADER
TOKEN_KEY

Public Class Methods

new(app) click to toggle source
     # File lib/action_dispatch/middleware/cookies.rb, line 290
290:     def initialize(app)
291:       @app = app
292:     end

Public Instance Methods

call(env) click to toggle source
     # File lib/action_dispatch/middleware/cookies.rb, line 294
294:     def call(env)
295:       status, headers, body = @app.call(env)
296: 
297:       if cookie_jar = env['action_dispatch.cookies']
298:         cookie_jar.write(headers)
299:         if headers[HTTP_HEADER].respond_to?(:join)
300:           headers[HTTP_HEADER] = headers[HTTP_HEADER].join("\n")
301:         end
302:       end
303: 
304:       [status, headers, body]
305:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.