Class: Compony::ModelFields::Attachment
- Defined in:
- lib/compony/model_fields/attachment.rb
Overview
Model field type representing an ActiveStorage attachment.
Instance Attribute Summary
Attributes inherited from Base
#extra_attrs, #model_class, #name, #schema_key
Instance Method Summary collapse
- #simpleform_input(form, _component, name: nil, accept: nil, **input_opts) ⇒ Object
- #value_for(data, controller: nil, **_) ⇒ Object
Methods inherited from Base
#association?, #initialize, #label, #multi?, #schema_line, #simpleform_input_hidden, #transform_and_join
Constructor Details
This class inherits a constructor from Compony::ModelFields::Base
Instance Method Details
#simpleform_input(form, _component, name: nil, accept: nil, **input_opts) ⇒ Object
14 15 16 17 |
# File 'lib/compony/model_fields/attachment.rb', line 14 def simpleform_input(form, _component, name: nil, accept: nil, **input_opts) input_opts.deep_merge!(input_html: { accept: }) if accept return form.input(name || @name, **input_opts) end |
#value_for(data, controller: nil, **_) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/compony/model_fields/attachment.rb', line 6 def value_for(data, controller: nil, **_) return transform_and_join(data.send(@name), controller:) do |el| fail('Must pass controller to generate the link to the attachment.') unless controller return nil unless el.attached? return controller.helpers.link_to(I18n.t('compony.model_fields.attachment.download'), controller.helpers.rails_blob_path(el)) end end |