Class: IronAdmin::Resources::ShowFieldComponent

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

Overview

Renders a single field value on the show page.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field:, record:, current_user: nil) ⇒ ShowFieldComponent

Returns a new instance of ShowFieldComponent.

Parameters:

  • field (IronAdmin::Field)

    Field config

  • record (ActiveRecord::Base)

    The record

  • current_user (Object, nil) (defaults to: nil)

    Current user



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

def initialize(field:, record:, current_user: nil)
  @field = field
  @record = record
  @current_user = current_user
end

Instance Attribute Details

#current_userObject? (readonly)

Returns Current user.

Returns:

  • (Object, nil)

    Current user



14
15
16
# File 'app/components/iron_admin/resources/show_field_component.rb', line 14

def current_user
  @current_user
end

#fieldIronAdmin::Field (readonly)

Returns The field configuration.

Returns:



8
9
10
# File 'app/components/iron_admin/resources/show_field_component.rb', line 8

def field
  @field
end

#recordActiveRecord::Base (readonly)

Returns The record.

Returns:

  • (ActiveRecord::Base)

    The record



11
12
13
# File 'app/components/iron_admin/resources/show_field_component.rb', line 11

def record
  @record
end

Instance Method Details

#labelString

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 Humanized field label.

Returns:

  • (String)

    Humanized field label



39
40
41
# File 'app/components/iron_admin/resources/show_field_component.rb', line 39

def label
  field.name.to_s.humanize
end

#render?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'app/components/iron_admin/resources/show_field_component.rb', line 25

def render?
  return false if field.type == :hidden

  field.visible?(@current_user)
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:



33
34
35
# File 'app/components/iron_admin/resources/show_field_component.rb', line 33

def theme
  IronAdmin.configuration.theme
end

#valueString?

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 Formatted field value.

Returns:

  • (String, nil)

    Formatted field value



45
46
47
# File 'app/components/iron_admin/resources/show_field_component.rb', line 45

def value
  helpers.display_field_value(record, field)
end