Class: IronAdmin::Resources::ActionsComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/iron_admin/resources/actions_component.rb

Overview

Renders the actions dropdown for a single record.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actions:, record:, resource_class:) ⇒ ActionsComponent

Returns a new instance of ActionsComponent.

Parameters:

  • actions (Array<Hash>)

    Actions to render

  • record (ActiveRecord::Base)

    The record

  • resource_class (Class)

    The resource



20
21
22
23
24
# File 'app/components/iron_admin/resources/actions_component.rb', line 20

def initialize(actions:, record:, resource_class:)
  @actions = actions
  @record = record
  @resource_class = resource_class
end

Instance Attribute Details

#actionsArray<Hash> (readonly)

Returns Defined actions.

Returns:

  • (Array<Hash>)

    Defined actions



9
10
11
# File 'app/components/iron_admin/resources/actions_component.rb', line 9

def actions
  @actions
end

#recordActiveRecord::Base (readonly)

Returns The record.

Returns:

  • (ActiveRecord::Base)

    The record



12
13
14
# File 'app/components/iron_admin/resources/actions_component.rb', line 12

def record
  @record
end

#resource_classClass (readonly)

Returns The resource class.

Returns:

  • (Class)

    The resource class



15
16
17
# File 'app/components/iron_admin/resources/actions_component.rb', line 15

def resource_class
  @resource_class
end

Instance Method Details

#action_url(action) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns URL for executing the action.

Parameters:

  • action (Hash)

    Action configuration

Returns:

  • (String)

    URL for executing the action



35
36
37
# File 'app/components/iron_admin/resources/actions_component.rb', line 35

def action_url(action)
  helpers.iron_admin.resource_action_path(resource_class.resource_name, record, action[:name])
end

#render?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Whether to render the component.

Returns:

  • (Boolean)

    Whether to render the component



41
42
43
# File 'app/components/iron_admin/resources/actions_component.rb', line 41

def render?
  actions.any?
end

#themeIronAdmin::Configuration::Theme

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Theme configuration.

Returns:



28
29
30
# File 'app/components/iron_admin/resources/actions_component.rb', line 28

def theme
  IronAdmin.configuration.theme
end