Class: ViewComponent::Juice::JuiceController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/view_component/juice/juice_controller.rb

Instance Method Summary collapse

Instance Method Details

#handle_updateObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/view_component/juice/juice_controller.rb', line 4

def handle_update
  component = juice_params[:component].constantize

  authenticables = {}

  if component.authenticate?
    component::AUTHENTICATE.each do |model|
      send "authenticate_#{model}!".to_sym
      
      name = "current_#{model}".to_sym

      authenticables[name] = send(name)
    end
  end

  component_instance = component.new(context: JSON.parse(juice_params[:context]), **authenticables)

  component_instance._update(juice_params[:message].to_sym)

  render component_instance, layout: nil
end