Class: IronAdmin::Resources::RelatedListComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- IronAdmin::Resources::RelatedListComponent
- Defined in:
- app/components/iron_admin/resources/related_list_component.rb
Overview
Renders a list of related records for has_many associations.
Instance Attribute Summary collapse
-
#association ⇒ Hash
readonly
Association configuration.
-
#limit ⇒ Integer
readonly
Max records to show.
-
#records ⇒ ActiveRecord::Relation
readonly
Related records.
Instance Method Summary collapse
-
#display_method ⇒ Symbol, ...
private
Display method for record labels.
-
#initialize(association:, records:, limit: 20) ⇒ RelatedListComponent
constructor
A new instance of RelatedListComponent.
-
#record_url(record) ⇒ String
private
URL to view the record.
-
#render? ⇒ Boolean
private
Whether to render the component.
-
#resource_name ⇒ String
private
Associated resource name.
-
#theme ⇒ IronAdmin::Configuration::Theme
private
Theme configuration.
-
#title ⇒ String
private
Humanized association title.
-
#view_all_url ⇒ String
private
URL to view all records.
Constructor Details
#initialize(association:, records:, limit: 20) ⇒ RelatedListComponent
Returns a new instance of RelatedListComponent.
19 20 21 22 23 |
# File 'app/components/iron_admin/resources/related_list_component.rb', line 19 def initialize(association:, records:, limit: 20) @association = association @records = records.limit(limit) @limit = limit end |
Instance Attribute Details
#association ⇒ Hash (readonly)
Returns Association configuration.
8 9 10 |
# File 'app/components/iron_admin/resources/related_list_component.rb', line 8 def association @association end |
#limit ⇒ Integer (readonly)
Returns Max records to show.
14 15 16 |
# File 'app/components/iron_admin/resources/related_list_component.rb', line 14 def limit @limit end |
#records ⇒ ActiveRecord::Relation (readonly)
Returns Related records.
11 12 13 |
# File 'app/components/iron_admin/resources/related_list_component.rb', line 11 def records @records end |
Instance Method Details
#display_method ⇒ Symbol, ...
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 Display method for record labels.
45 46 47 |
# File 'app/components/iron_admin/resources/related_list_component.rb', line 45 def display_method association[:display] end |
#record_url(record) ⇒ 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 to view the record.
58 59 60 |
# File 'app/components/iron_admin/resources/related_list_component.rb', line 58 def record_url(record) helpers.iron_admin.resource_path(resource_name, record) 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.
64 65 66 |
# File 'app/components/iron_admin/resources/related_list_component.rb', line 64 def render? records.any? end |
#resource_name ⇒ 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 Associated resource name.
39 40 41 |
# File 'app/components/iron_admin/resources/related_list_component.rb', line 39 def resource_name association[:resource].resource_name end |
#theme ⇒ IronAdmin::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.
27 28 29 |
# File 'app/components/iron_admin/resources/related_list_component.rb', line 27 def theme IronAdmin.configuration.theme end |
#title ⇒ 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 Humanized association title.
33 34 35 |
# File 'app/components/iron_admin/resources/related_list_component.rb', line 33 def title association[:name].to_s.humanize end |
#view_all_url ⇒ 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 to view all records.
51 52 53 |
# File 'app/components/iron_admin/resources/related_list_component.rb', line 51 def view_all_url helpers.iron_admin.resources_path(resource_name) end |