Class: RubyUIAdmin::Fields::FilesField
- Defined in:
- lib/ruby_ui_admin/fields/files_field.rb
Overview
Multiple ActiveStorage attachments (has_many_attached).
Instance Attribute Summary
Attributes inherited from BaseField
#block, #id, #options, #resource
Instance Method Summary collapse
- #attachments(record) ⇒ Object
-
#fill(record, attributes) ⇒ Object
Purge the attachments the user checked, then APPEND any new uploads (unlike the single
:file, new files don't replace the existing set). - #multiple? ⇒ Boolean
-
#permit_param ⇒ Object
Submitted as an array (record[]).
-
#permit_params ⇒ Object
Permit the upload array plus the array of attachment ids to remove.
-
#remove_ids_param ⇒ Object
Form param holding the ids of attachments marked for removal.
Methods inherited from FileField
#accept, #attached?, #attachment, #default_hidden_views, #fill_value, #preview_size, #remove_param
Methods inherited from BaseField
#database_id, #default_hidden_views, #default_value, #description, field_type, #fill_value, #filterable?, #formatted_value, #has_default?, #help, #initialize, #link_to_record?, #name, #permitted_param, #placeholder, #readonly?, register_as, #required?, #sort_lambda, #sortable?, #type, #value, #visible?, #visible_in_view?
Constructor Details
This class inherits a constructor from RubyUIAdmin::Fields::BaseField
Instance Method Details
#attachments(record) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/ruby_ui_admin/fields/files_field.rb', line 28 def (record) att = (record) return [] unless att.respond_to?(:attached?) && att.attached? att end |
#fill(record, attributes) ⇒ Object
Purge the attachments the user checked, then APPEND any new uploads (unlike the single
:file, new files don't replace the existing set). Both skip blanks/empties.
37 38 39 40 |
# File 'lib/ruby_ui_admin/fields/files_field.rb', line 37 def fill(record, attributes) purge_marked(record, attributes[remove_ids_param.to_s]) attach_new(record, attributes[permitted_param.to_s]) end |
#multiple? ⇒ Boolean
9 10 11 |
# File 'lib/ruby_ui_admin/fields/files_field.rb', line 9 def multiple? true end |
#permit_param ⇒ Object
Submitted as an array (record[]).
14 15 16 |
# File 'lib/ruby_ui_admin/fields/files_field.rb', line 14 def permit_param {permitted_param => []} end |
#permit_params ⇒ Object
Permit the upload array plus the array of attachment ids to remove.
24 25 26 |
# File 'lib/ruby_ui_admin/fields/files_field.rb', line 24 def permit_params [permit_param, {remove_ids_param => []}] end |
#remove_ids_param ⇒ Object
Form param holding the ids of attachments marked for removal.
19 20 21 |
# File 'lib/ruby_ui_admin/fields/files_field.rb', line 19 def remove_ids_param :"#{permitted_param}_remove_ids" end |