Class: Avo::Fields::FilesField
- Defined in:
- lib/avo/fields/files_field.rb
Defined Under Namespace
Classes: EditComponent, IndexComponent, ShowComponent
Instance Attribute Summary collapse
-
#direct_upload ⇒ Object
Returns the value of attribute direct_upload.
-
#is_image ⇒ Object
Returns the value of attribute is_image.
Attributes inherited from BaseField
#action, #as_avatar, #as_description, #as_label, #block, #computable, #computed, #computed_value, #default, #format_using, #help, #id, #model, #null_values, #nullable, #panel_name, #readonly, #required, #resource, #sortable, #updatable, #user, #view, #visible
Attributes included from Avo::Fields::FieldExtensions::VisibleInDifferentViews
#show_on_edit, #show_on_index, #show_on_new, #show_on_show
Instance Method Summary collapse
- #fill_field(model, key, value, params) ⇒ Object
-
#initialize(id, **args, &block) ⇒ FilesField
constructor
A new instance of FilesField.
- #to_permitted_param ⇒ Object
- #view_component_name ⇒ Object
Methods inherited from BaseField
#component_for_view, #custom?, #database_id, #has_own_panel?, #hydrate, #model_errors, #name, #placeholder, #resolve_attribute, #translation_key, #type, #value, #visible?
Methods included from Avo::Fields::FieldExtensions::HasFieldName
Methods included from Avo::Fields::FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on
Constructor Details
#initialize(id, **args, &block) ⇒ FilesField
Returns a new instance of FilesField.
7 8 9 10 11 12 |
# File 'lib/avo/fields/files_field.rb', line 7 def initialize(id, **args, &block) super(id, **args, &block) @is_image = args[:is_image].present? ? args[:is_image] : @is_avatar @direct_upload = args[:direct_upload].present? ? args[:direct_upload] : false end |
Instance Attribute Details
#direct_upload ⇒ Object
Returns the value of attribute direct_upload.
5 6 7 |
# File 'lib/avo/fields/files_field.rb', line 5 def direct_upload @direct_upload end |
#is_image ⇒ Object
Returns the value of attribute is_image.
4 5 6 |
# File 'lib/avo/fields/files_field.rb', line 4 def is_image @is_image end |
Instance Method Details
#fill_field(model, key, value, params) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/avo/fields/files_field.rb', line 22 def fill_field(model, key, value, params) return model unless model.methods.include? key.to_sym value.each do |file| # Skip empty values next unless file.present? model.send(key).attach file end model end |
#to_permitted_param ⇒ Object
18 19 20 |
# File 'lib/avo/fields/files_field.rb', line 18 def to_permitted_param {"#{id}": []} end |
#view_component_name ⇒ Object
14 15 16 |
# File 'lib/avo/fields/files_field.rb', line 14 def view_component_name "FilesField" end |