Permalink
Browse files

Correct example in cookies docs. Closes #5832.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4793 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 70577d0 commit 04d2d5f2884677542b7062ece98bd91978e78b2b @jeremy jeremy committed Aug 20, 2006
Showing with 10 additions and 7 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +8 −7 actionpack/lib/action_controller/cookies.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Correct example in cookies docs. #5832 [jessemerriman@warpmail.net]
+
* Updated to script.aculo.us 1.6.2 [Thomas Fuchs]
* Relax Routing's anchor pattern warning; it was preventing use of [^/] inside restrictions. [Nicholas Seckar]
@@ -4,13 +4,14 @@ module ActionController #:nodoc:
# itself back -- just the value it holds). Examples for writing:
#
# cookies[:user_name] = "david" # => Will set a simple session cookie
- # cookies[:login] = { :value => "XJ-122", :expires => Time.now + 360} # => Will set a cookie that expires in 1 hour
- #
+ # cookies[:login] = { :value => "XJ-122", :expires => 1.hour.from_now }
+ # # => Will set a cookie that expires in 1 hour
+ #
# Examples for reading:
#
# cookies[:user_name] # => "david"
# cookies.size # => 2
- #
+ #
# Example for deleting:
#
# cookies.delete :user_name
@@ -35,7 +36,7 @@ def cookie(*options)
@response.headers["cookie"] << CGI::Cookie.new(*options)
end
end
-
+
class CookieJar < Hash #:nodoc:
def initialize(controller)
@controller, @cookies = controller, controller.instance_variable_get("@cookies")
@@ -48,18 +49,18 @@ def initialize(controller)
def [](name)
@cookies[name.to_s].value.first if @cookies[name.to_s] && @cookies[name.to_s].respond_to?(:value)
end
-
+
def []=(name, options)
if options.is_a?(Hash)
options = options.inject({}) { |options, pair| options[pair.first.to_s] = pair.last; options }
options["name"] = name.to_s
else
options = { "name" => name.to_s, "value" => options }
end
-
+
set_cookie(options)
end
-
+
# Removes the cookie on the client machine by setting the value to an empty string
# and setting its expiration date into the past
def delete(name)

0 comments on commit 04d2d5f

Please sign in to comment.