public
Description: Repository for improving Rails documentation
Homepage: http://www.rubyonrails.org
Clone URL: git://github.com/lifo/doc-rails.git
Search Repo:
revised documentation of cookies.rb
Xavier Noria (author)
Sun Apr 20 11:27:10 -0700 2008
commit  8f47958d0ae15a046d3392b62042bd5500824258
tree    3a2f9c0eb461454e4ff360c64763ed9672b291f4
parent  cc8439ef961e2493b791b752c942bf3b7153cd89
...
1
2
3
4
 
5
6
 
 
 
 
 
 
 
 
 
 
7
8
9
10
11
12
13
 
14
15
16
17
18
19
 
20
21
22
23
24
25
26
27
28
 
 
 
 
 
 
 
 
 
29
30
31
...
45
46
47
48
49
 
50
51
52
...
54
55
56
 
 
57
58
59
60
...
66
67
68
69
70
 
 
71
72
73
74
75
76
 
 
 
 
77
78
79
...
1
 
 
 
2
3
 
4
5
6
7
8
9
10
11
12
13
14
 
15
16
17
18
 
19
20
21
22
23
24
 
25
26
 
 
 
 
 
 
 
 
27
28
29
30
31
32
33
34
35
36
37
38
...
52
53
54
 
 
55
56
57
58
...
60
61
62
63
64
65
66
67
68
...
74
75
76
 
 
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
0
@@ -1,31 +1,38 @@
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
   #
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
+ #
0
+ # Examples for writing:
0
+ #
0
+ # # Sets a simple session cookie.
0
+ # cookies[:user_name] = "david"
0
+ #
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
   #
0
   # Examples for reading:
0
   #
0
   # cookies[:user_name] # => "david"
0
- # cookies.size # => 2
0
+ # cookies.size # => 2
0
   #
0
   # Example for deleting:
0
   #
0
   # cookies.delete :user_name
0
   #
0
- # All the option symbols for setting cookies are:
0
+ # The option symbols for setting cookies are:
0
   #
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
-
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
+ # 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 only transmitted to HTTPS servers.
0
+ # Default is +false+.
0
+ # * <tt>:http_only</tt> - Whether this cookie is accessible via scripting or
0
+ # only HTTP. Defaults to +false+.
0
   module Cookies
0
     def self.included(base)
0
       base.helper_method :cookies
0
@@ -45,8 +52,7 @@
0
       update(@cookies)
0
     end
0
 
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
     def [](name)
0
       cookie = @cookies[name.to_s]
0
       if cookie && cookie.respond_to?(:value)
0
@@ -54,6 +60,8 @@
0
       end
0
     end
0
 
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
     def []=(name, options)
0
       if options.is_a?(Hash)
0
         options = options.inject({}) { |options, pair| options[pair.first.to_s] = pair.last; options }
0
0
@@ -66,14 +74,18 @@
0
     end
0
 
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
     end
0
 
0
     private
0
+ # Builds a CGI::Cookie object and adds the cookie to the response headers.
0
+ #
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.