Module: Hanami::Action::Session

Defined in:
gems/gems/hanami-controller-1.3.2/lib/hanami/action/session.rb,
gems/gems/hanami-controller-1.3.3/lib/hanami/action/session.rb

Overview

Session API

This module isn’t included by default.

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#errorsHanami::Validations::Errors

Read errors from flash or delegate to the superclass

Returns:

  • (Hanami::Validations::Errors)

    A collection of validation errors

See Also:

Since:

  • 0.3.0

def errors
  flash[ERRORS_KEY] || params.respond_to?(:errors) && params.errors
end

#flashHanami::Action::Flash (private)

Container useful to transport data with the HTTP session

Returns:

  • (Hanami::Action::Flash)

    a Flash instance

See Also:

Since:

  • 0.3.0

def flash
  @flash ||= Flash.new(session)
end

#sessionHash

Gets the session from the request and expose it as an Hash.

Examples:

require 'hanami/controller'
require 'hanami/action/session'

class Show
  include Hanami::Action
  include Hanami::Action::Session

  def call(params)
    # ...

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

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

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

Returns:

  • (Hash)

    the HTTP session from the request

Since:

  • 0.1.0

def session
  @_env[SESSION_KEY] ||= {}
end