Class: Alchemy::Admin::Filters::Select

Inherits:
Base
  • Object
show all
Defined in:
app/models/alchemy/admin/filters/select.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#name, #resource_name

Instance Method Summary collapse

Methods inherited from Base

#applied_filter_component

Constructor Details

#initialize(name:, resource_name:, options:) ⇒ Select

Creates a resource filter that displays as a select.

Parameters:

  • name (String)

    The name of the filter.

  • resource_name (String)

    The name of the resource.

  • options (Proc, Array)

    A proc that returns the options for the select, or an array of options.



13
14
15
16
# File 'app/models/alchemy/admin/filters/select.rb', line 13

def initialize(name:, resource_name:, options:)
  super(name:, resource_name:)
  @options = options_to_proc(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'app/models/alchemy/admin/filters/select.rb', line 7

def options
  @options
end

Instance Method Details

#input_component(params, query) ⇒ Alchemy::Admin::Resource::SelectFilter

Returns a select filter component.

Parameters:

  • params (Hash)

    The search filter params.

  • query (Ransack::Search)

    The current search query.

Returns:



22
23
24
25
26
27
28
29
30
31
# File 'app/models/alchemy/admin/filters/select.rb', line 22

def input_component(params, query)
  Alchemy::Admin::Resource::SelectFilter.new(
    name:,
    resource_name:,
    label: translated_name,
    include_blank:,
    options: get_options_for_select(query),
    params:
  )
end