Sha256: 0cf195095a7b72b8845ebd12df23bb32975f511c801cdeeebac8dc80c40c46e0
Contents?: true
Size: 1.28 KB
Versions: 4
Compression:
Stored size: 1.28 KB
Contents
require_relative "inertia_rails" require_relative "helper" module InertiaRails module Controller extend ActiveSupport::Concern included do before_action do # :inertia_errors are deleted from the session by the middleware InertiaRails.share(errors: session[:inertia_errors]) if session[:inertia_errors].present? end helper ::InertiaRails::Helper end module ClassMethods def inertia_share(**args, &block) before_action do InertiaRails.share(**args) if args InertiaRails.share_block(block) if block end end end def redirect_to(options = {}, response_options = {}) capture_inertia_errors(response_options) super(options, response_options) end def redirect_back(fallback_location:, allow_other_host: true, **options) capture_inertia_errors(options) super( fallback_location: fallback_location, allow_other_host: allow_other_host, **options, ) end private def inertia_location(url) headers['X-Inertia-Location'] = url head :conflict end def capture_inertia_errors(options) if (inertia_errors = options.dig(:inertia, :errors)) session[:inertia_errors] = inertia_errors end end end end
Version data entries
4 entries across 4 versions & 1 rubygems