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
– or nil if no such cookie exist. - #[]=(name, options) ⇒ Object
-
#delete(name) ⇒ Object
Removes the cookie on the client machine by setting the value to an empty string.
-
#initialize(controller) ⇒ CookieJar
constructor
A new instance of CookieJar.
Constructor Details
#initialize(controller) ⇒ CookieJar
Returns a new instance of CookieJar.
34 35 36 37 38 |
# File 'lib/action_controller/cookies.rb', line 34 def initialize(controller) @controller, @cookies = controller, controller.instance_variable_get("@cookies") super() update(@cookies) end |
Instance Method Details
#[](name) ⇒ Object
Returns the value of the cookie by name
– or nil if no such cookie exist. You set new cookies using either the cookie method or cookies[]= (for simple name/value cookies without options).
42 43 44 |
# File 'lib/action_controller/cookies.rb', line 42 def [](name) @cookies[name.to_s].value.first if @cookies[name.to_s] && @cookies[name.to_s].respond_to?(:value) end |
#[]=(name, options) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/action_controller/cookies.rb', line 46 def []=(name, ) if .is_a?(Hash) = .inject({}) { |, pair| [pair.first.to_s] = pair.last; } ["name"] = name.to_s else = { "name" => name, "value" => } end (name, ) end |
#delete(name) ⇒ Object
Removes the cookie on the client machine by setting the value to an empty string.
58 59 60 |
# File 'lib/action_controller/cookies.rb', line 58 def delete(name) (name, "name" => name, "value" => "") end |