Class: Avo::Fields::FileField
- Defined in:
- lib/avo/app/fields/file_field.rb
Instance Attribute Summary collapse
-
#is_avatar ⇒ Object
Returns the value of attribute is_avatar.
-
#is_image ⇒ Object
Returns the value of attribute is_image.
Attributes inherited from Field
#block, #component, #computable, #default, #format_using, #help, #id, #is_array_param, #is_object_param, #name, #null_values, #nullable, #placeholder, #readonly, #required, #sortable, #updatable
Attributes included from Avo::Fields::FieldExtensions::VisibleOnDifferentViews
#show_on_create, #show_on_edit, #show_on_index, #show_on_show
Instance Method Summary collapse
- #hydrate_field(fields, model, resource, view) ⇒ Object
-
#initialize(name, **args, &block) ⇒ FileField
constructor
A new instance of FileField.
Methods inherited from Field
#database_id, #fetch_for_action, #fetch_for_resource, #fill_field, #has_own_panel?, #resolve_attribute
Methods included from Avo::Fields::FieldExtensions::HasFieldName
#field_name, #field_name_attribute, #get_field_name
Methods included from Avo::Fields::FieldExtensions::VisibleOnDifferentViews
#except_on, #hide_on, #only_on, #show_on
Constructor Details
#initialize(name, **args, &block) ⇒ FileField
Returns a new instance of FileField.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/avo/app/fields/file_field.rb', line 8 def initialize(name, **args, &block) @defaults = { component: 'file-field', }.merge(@defaults || {}) super(name, **args, &block) @file_field = true @is_avatar = args[:is_avatar].present? ? args[:is_avatar] : false @is_image = args[:is_image].present? ? args[:is_image] : @is_avatar end |
Instance Attribute Details
#is_avatar ⇒ Object
Returns the value of attribute is_avatar.
5 6 7 |
# File 'lib/avo/app/fields/file_field.rb', line 5 def is_avatar @is_avatar end |
#is_image ⇒ Object
Returns the value of attribute is_image.
6 7 8 |
# File 'lib/avo/app/fields/file_field.rb', line 6 def is_image @is_image end |
Instance Method Details
#hydrate_field(fields, model, resource, view) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/avo/app/fields/file_field.rb', line 19 def hydrate_field(fields, model, resource, view) storage_field = model.send(id) field = { value: nil } return field unless storage_field.attached? field[:filename] = storage_field.filename field[:value] = rails_blob_url(storage_field, only_path: true) field[:is_image] = self.is_image field end |