Class: ActionController::CookieJar
- Defined in:
- lib/action_controller/cookies.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#[](name) ⇒ Object
Returns the value of the cookie by
name
, ornil
if no such cookie exists. -
#[]=(key, options) ⇒ Object
Sets the cookie named
name
. -
#delete(key, options = {}) ⇒ Object
Removes the cookie on the client machine by setting the value to an empty string and setting its expiration date into the past.
-
#initialize(controller) ⇒ CookieJar
constructor
A new instance of CookieJar.
Constructor Details
#initialize(controller) ⇒ CookieJar
Returns a new instance of CookieJar.
59 60 61 62 63 |
# File 'lib/action_controller/cookies.rb', line 59 def initialize(controller) @controller, @cookies = controller, controller.request. super() update(@cookies) end |
Instance Method Details
#[](name) ⇒ Object
Returns the value of the cookie by name
, or nil
if no such cookie exists.
66 67 68 |
# File 'lib/action_controller/cookies.rb', line 66 def [](name) super(name.to_s) end |
#[]=(key, options) ⇒ Object
Sets the cookie named name
. The second argument may be the very cookie value, or a hash of options as documented above.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/action_controller/cookies.rb', line 72 def []=(key, ) if .is_a?(Hash) .symbolize_keys! else = { :value => } end [:path] = "/" unless .has_key?(:path) super(key.to_s, [:value]) @controller.response.(key, ) end |
#delete(key, options = {}) ⇒ Object
Removes the cookie on the client machine by setting the value to an empty string and setting its expiration date into the past. Like []=
, you can pass in an options hash to delete cookies with extra data such as a :path
.
87 88 89 90 91 92 |
# File 'lib/action_controller/cookies.rb', line 87 def delete(key, = {}) .symbolize_keys! [:path] = "/" unless .has_key?(:path) super(key.to_s) @controller.response.(key, ) end |