Class: CrudComponents::Fields::AttachmentField
- Inherits:
-
Base
- Object
- Base
- CrudComponents::Fields::AttachmentField
show all
- Defined in:
- lib/crud_components/fields/attachment_field.rb
Overview
Active Storage attachment: rendered by content type — image inline,
previewable (e.g. PDF) as a preview, otherwise an icon + filename link.
Constant Summary
Constants inherited
from Base
Base::NON_EDITABLE_COLUMNS
Instance Attribute Summary
Attributes inherited from Base
#facets, #model, #name, #options
Instance Method Summary
collapse
Methods inherited from Base
#apply_filter, #apply_filter_facet, #apply_sort, #column, #custom_header?, #declared_preloads, #derived_sortable?, #editable?, #editable_permitted?, #filter_choices, #filter_control, #filter_facet, #filter_includes_null?, #filterable?, #form_partial, #group_label, #group_model, #header, #header_actions, #human_name, #initialize, #nullable?, #permitted?, #picker_label, #range_filter?, #render_block, #renderer, #renderer_options, #search_spec_entry, #sort_facet, #sortable?, #typed_filter, #value
Instance Method Details
#apply_derived_filter(scope, value: nil) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/crud_components/fields/attachment_field.rb', line 24
def apply_derived_filter(scope, value: nil, **)
case value
when CrudComponents::PRESENT_FILTER_VALUE then scope.where.associated(attachment_reflection)
when CrudComponents::ABSENT_FILTER_VALUE then scope.where.missing(attachment_reflection)
else scope
end
end
|
#default_editable? ⇒ Boolean
── forms ────────────────────────────────────────────────────────────
33
|
# File 'lib/crud_components/fields/attachment_field.rb', line 33
def default_editable? = true
|
#default_renderer ⇒ Object
6
|
# File 'lib/crud_components/fields/attachment_field.rb', line 6
def default_renderer = :attachment
|
#derived_filter_control ⇒ Object
22
|
# File 'lib/crud_components/fields/attachment_field.rb', line 22
def derived_filter_control = :presence
|
#derived_filterable? ⇒ Boolean
── filtering ──────────────────────────────────────────────────────────
An attachment has no value to type into a box, but "has a cover / has no
cover" is the natural question — so it filters by presence: a 3-state
any/present/absent control that composes into the query as an EXISTS /
NOT EXISTS over the backing *_attachment(s) association.
21
|
# File 'lib/crud_components/fields/attachment_field.rb', line 21
def derived_filterable? = true
|
#eager_load ⇒ Object
12
13
14
|
# File 'lib/crud_components/fields/attachment_field.rb', line 12
def eager_load
[attachment_reflection, *declared_preloads]
end
|
34
|
# File 'lib/crud_components/fields/attachment_field.rb', line 34
def form_control = :file
|
#many? ⇒ Boolean
8
9
10
|
# File 'lib/crud_components/fields/attachment_field.rb', line 8
def many?
@many ||= model.reflect_on_attachment(name).macro == :has_many_attached
end
|
#permit_param ⇒ Object
35
|
# File 'lib/crud_components/fields/attachment_field.rb', line 35
def permit_param = many? ? { name => [] } : name
|