Class: Koi::Tables::Body::AttachmentComponent
- Inherits:
-
Koi::Tables::BodyCellComponent
- Object
- Katalyst::Tables::BodyCellComponent
- Koi::Tables::BodyCellComponent
- Koi::Tables::Body::AttachmentComponent
- Defined in:
- app/components/koi/tables/body.rb
Overview
Shows an attachment
The value is expected to be an ActiveStorage attachment
If it is representable, shows as a image tag using a default variant named :thumb.
Otherwise shows as a link to download.
Instance Method Summary collapse
- #filename ⇒ Object
-
#initialize(table, record, attribute, variant: :thumb, **options) ⇒ AttachmentComponent
constructor
A new instance of AttachmentComponent.
-
#internal_path ⇒ Object
Utility for accessing the path Rails provides for retrieving the attachment for use in cells.
- #rendered_value ⇒ Object
- #representation ⇒ Object
Methods inherited from Koi::Tables::BodyCellComponent
Constructor Details
#initialize(table, record, attribute, variant: :thumb, **options) ⇒ AttachmentComponent
Returns a new instance of AttachmentComponent.
186 187 188 189 190 |
# File 'app/components/koi/tables/body.rb', line 186 def initialize(table, record, attribute, variant: :thumb, **) super(table, record, attribute, **) @variant = variant end |
Instance Method Details
#filename ⇒ Object
206 207 208 |
# File 'app/components/koi/tables/body.rb', line 206 def filename value.blob.filename end |
#internal_path ⇒ Object
Utility for accessing the path Rails provides for retrieving the attachment for use in cells. Example:
<% row.attachment :file do |cell| %>
<%= link_to "Download", cell.internal_path %>
<% end %>
215 216 217 |
# File 'app/components/koi/tables/body.rb', line 215 def internal_path rails_blob_path(value, disposition: :attachment) end |
#rendered_value ⇒ Object
192 193 194 |
# File 'app/components/koi/tables/body.rb', line 192 def rendered_value representation end |
#representation ⇒ Object
196 197 198 199 200 201 202 203 204 |
# File 'app/components/koi/tables/body.rb', line 196 def representation if value.try(:variable?) && named_variant.present? image_tag(value.variant(@variant)) elsif value.try(:attached?) filename.to_s else "" end end |