Module: InertiaHanami::Action

Defined in:
lib/inertia_hanami/action.rb

Overview

Include-able into Hanami::Action subclasses to speak the Inertia protocol: skips Hanami's automatic view rendering for Inertia XHR requests, renders the Inertia page envelope, accumulates shared props, and handles the external-redirect (409 + X-Inertia-Location) case.

Follows Hanami's own composition idiom (include Inertia::Action) rather than requiring a subclass of a framework-specific base class.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Constant Summary collapse

INERTIA_ERRORS_SESSION_KEY =

Session key used to stash validation errors across a redirect, mirroring inertia-rails' session[:inertia_errors]. Cleared as soon as it's read into the next response's errors prop.

"inertia_errors"

Class Method Summary collapse

Class Method Details

.included(action_class) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/inertia_hanami/action.rb', line 17

def self.included(action_class)
  super

  action_class.extend(ClassMethods)
  action_class.include(InstanceMethods)

  action_class.append_before do |req, res|
    @inertia_context[:request] = req
    @inertia_context[:response] = res
  end

  share_errors_and_flash(action_class)
end