Module: UniversalRenderer::Renderable::ClassMethods

Defined in:
lib/universal_renderer/renderable.rb

Instance Method Summary collapse

Instance Method Details

#enable_ssr(options = {}) ⇒ void

This method returns an undefined value.

Arms the automatic render path for this controller.

Examples:

Public pages only

enable_ssr only: :show, unless: -> { current_user.present? }

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :streaming (Boolean)

    Stream the response instead of fetching it in one blocking request. Mixes in ActionController::Live.

  • :only (Symbol, Array<Symbol>)

    Restrict to these actions.

  • :except (Symbol, Array<Symbol>)

    Skip these actions.

  • :if (Symbol, Proc)

    Render only when this evaluates truthy. A Symbol names a controller method; a Proc is instance_exec'd against the controller.

  • :unless (Symbol, Proc)

    Skip when this evaluates truthy.



45
46
47
48
49
50
51
# File 'lib/universal_renderer/renderable.rb', line 45

def enable_ssr(options = {})
  self.ssr_enabled = true
  self.ssr_streaming_preference = options[:streaming]
  self.ssr_conditions = options.slice(:only, :except, :if, :unless).freeze

  include UniversalRenderer::Renderable::Streaming if options[:streaming]
end