Module: Hanami::Action::Cookies

Defined in:
lib/hanami/action/cookies.rb

Overview

Cookies API

This module isn't included by default.

See Also:

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#cookiesHanami::Action::CookieJar (protected)

Gets the cookies from the request and expose them as an Hash

It automatically sets options from global configuration, but it allows to override values case by case.

For a list of options please have a look at Hanami::Controller::Configuration, and Hanami::Action::CookieJar.

Examples:

Basic Usage

require 'hanami/controller'
require 'hanami/action/cookies'

class Show
  include Hanami::Action
  include Hanami::Action::Cookies

  def call(params)
    # ...

    # get a value
    cookies[:user_id] # => '23'

    # set a value
    cookies[:foo] = 'bar'

    # remove a value
    cookies[:bax] = nil
  end
end

Cookies Options

require 'hanami/controller'
require 'hanami/action/cookies'

class Show
  include Hanami::Action
  include Hanami::Action::Cookies

  def call(params)
    # ...
    # set a value
    cookies[:foo] = { value: 'bar', max_age: 300, path: '/dashboard' }
  end
end

Returns:

See Also:

Since:

  • 0.1.0


67
68
69
# File 'lib/hanami/action/cookies.rb', line 67

def cookies
  @cookies ||= CookieJar.new(@_env.dup, headers, configuration.cookies)
end