0
module ActionController #:nodoc:
0
- # Cookies are read and written through ActionController#cookies. The cookies being read are what were received along with the request,
0
- # the cookies being written are what will be sent out with the response. Cookies are read by value (so you won't get the cookie object
0
- # itself back -- just the value it holds). Examples for writing:
0
+ # Cookies are read and written through ActionController#cookies.
0
- # cookies[:user_name] = "david" # => Will set a simple session cookie
0
+ # The cookies being read are the ones received along with the request, the cookies
0
+ # being written will be sent out with the response. Reading a cookie does not get
0
+ # the cookie object itself back, just the value it holds.
0
+ # Examples for writing:
0
+ # # Sets a simple session cookie.
0
+ # cookies[:user_name] = "david"
0
+ # # Sets a cookie that expires in 1 hour.
0
# cookies[:login] = { :value => "XJ-122", :expires => 1.hour.from_now }
0
- # # => Will set a cookie that expires in 1 hour
0
# Examples for reading:
0
# cookies[:user_name] # => "david"
0
# Example for deleting:
0
# cookies.delete :user_name
0
- #
All the option symbols for setting cookies are:
0
+ #
The option symbols for setting cookies are:
0
- # * <tt>value</tt> - the cookie's value or list of values (as an array).
0
- # * <tt>path</tt> - the path for which this cookie applies. Defaults to the root of the application.
0
- # * <tt>domain</tt> - the domain for which this cookie applies.
0
- # * <tt>expires</tt> - the time at which this cookie expires, as a +Time+ object.
0
- # * <tt>secure</tt> - whether this cookie is a secure cookie or not (default to false).
0
- # Secure cookies are only transmitted to HTTPS servers.
0
- # * <tt>http_only</tt> - whether this cookie is accessible via scripting or only HTTP (defaults to false).
0
+ # * <tt>:value</tt> - The cookie's value or list of values (as an array).
0
+ # * <tt>:path</tt> - The path for which this cookie applies. Defaults to the root
0
+ # * <tt>:domain</tt> - The domain for which this cookie applies.
0
+ # * <tt>:expires</tt> - The time at which this cookie expires, as a Time object.
0
+ # * <tt>:secure</tt> - Whether this cookie is a only transmitted to HTTPS servers.
0
+ # * <tt>:http_only</tt> - Whether this cookie is accessible via scripting or
0
+ # only HTTP. Defaults to +false+.
0
def self.included(base)
0
base.helper_method :cookies
0
- # Returns the value of the cookie by +name+ -- or nil if no such cookie exists. You set new cookies using cookies[]=
0
- # (for simple name/value cookies without options).
0
+ # Returns the value of the cookie by +name+, or +nil+ if no such cookie exists.
0
cookie = @cookies[name.to_s]
0
if cookie && cookie.respond_to?(:value)
0
+ # Sets the cookie named +name+. The second argument may be the very cookie
0
+ # value, or a hash of options as documented above.
0
options = options.inject({}) { |options, pair| options[pair.first.to_s] = pair.last; options }
0
# Removes the cookie on the client machine by setting the value to an empty string
0
- # and setting its expiration date into the past. Like []=, you can pass in an options
0
- # hash to delete cookies with extra data such as a +path+.
0
+ # and setting its expiration date into the past. Like <tt>[]=</tt>, you can pass in
0
+ # an options hash to delete cookies with extra data such as a <tt>:path</tt>.
0
def delete(name, options = {})
0
options.stringify_keys!
0
set_cookie(options.merge("name" => name.to_s, "value" => "", "expires" => Time.at(0)))
0
+ # Builds a CGI::Cookie object and adds the cookie to the response headers.
0
+ # The path of the cookie defaults to "/" if there's none in +options+, and
0
+ # everything is passed to the CGI::Cookie constructor.
0
def set_cookie(options) #:doc:
0
options["path"] = "/" unless options["path"]
0
cookie = CGI::Cookie.new(options)
Comments
No one has commented yet.