class method
self.new
Ruby on Rails 2.2.3
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
self.new(name = '', *value)
Creates a new CGI::Cookie object.
The contents of the cookie can be specified as a name and one or more value arguments. Alternatively, the contents can be specified as a single hash argument. The possible keywords of this hash are as follows:
-
:name- The name of the cookie. Required. -
:value- The cookie’s value or list of values. -
:path- The path for which this cookie applies. Defaults to the base directory of the CGI script. -
:domain- The domain for which this cookie applies. -
:expires- The time at which this cookie expires, as a Time object. -
:secure- Whether this cookie is a secure cookie or not (defaults tofalse). Secure cookies are only transmitted to HTTPS servers. -
:http_only- Whether this cookie can be accessed by client side scripts (e.g. document.cookie) or only over HTTP. More details in msdn2.microsoft.com/en-us/library/system.web.httpcookie.httponly.aspx. Defaults tofalse.
These keywords correspond to attributes of the cookie object.
Parameters
-
nameopt = '' -
valuerest
Source
# File actionpack/lib/action_controller/cgi_ext/cookie.rb, line 28
def initialize(name = '', *value)
if name.kind_of?(String)
@name = name
@value = Array(value)
@domain = nil
@expires = nil
@secure = false
@http_only = false
@path = nil
else
@name = name['name']
@value = (name['value'].kind_of?(String) ? [name['value']] : Array(name['value'])).delete_if(&:blank?)
@domain = name['domain']
@expires = name['expires']
@secure = name['secure'] || false
@http_only = name['http_only'] || false
@path = name['path']
end
raise ArgumentError, "`name' required" unless @name
# simple support for IE
unless @path
%r|^(.*/)|.match(ENV['SCRIPT_NAME'])
@path = ($1 or '')
end
super(@value)
end
Defined in actionpack/lib/action_controller/cgi_ext/cookie.rb line 28
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in CGI::Cookie