Class: Uchi::BelongsTo::AssociatedRecordsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/uchi/belongs_to/associated_records_controller.rb

Overview

Companion controller for the Stimulus-based belongs_to_controller.

Provides backend support for fetching associated records for a belongs_to field via AJAX.

Instance Method Summary collapse

Instance Method Details

#index ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/uchi/belongs_to/associated_records_controller.rb', line 15

def index
  @current_value = field.value(parent_record)

  @field_name = params[:field]
  @records = Uchi::CallWithFlexibleArguments
    .new(field.collection_query)
    .call(
      context: uchi_context,
      query: find_all_records_from_association
    )
end