- to preview pdf files you need to install
mupdf
orPoppler
. - to preview video files you need to install
ffmpeg
.
Add administrate-field-active_storage
to your Gemfile:
gem 'administrate-field-active_storage'
Install:
$ bundle install
assuming your modelname is Model
and field name is attachment
class ModelDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
attachment: Field::ActiveStorage,
}
# ...
Then add :attachment
to FORM_ATTRIBUTES
and SHOW_PAGE_ATTRIBUTES
.
currently adding :attachment
COLLECTION_ATTRIBUTES
will work but will probably look too big.
assuming your modelname is Model
and field name is attachments
the processs is identical the only issue is that the form field isn't being permitted, in order to permit it we apply the following method to the dashboard:
class ModelDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
attachments: Field::ActiveStorage,
}
# ...
FORM_ATTRIBUTES = {
#...
:attachments
}
# permitted for has_many_attached
def permitted_attributes
super + [:attachments => []]
end
i know it is not ideal, if you have a workaround please submit a PR
only the following needs to change in order for the field to be url_only
class ModelDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
attachments: Field::ActiveStorage.with_options({url_only: true}),
# ...
}
# ...
end
- upload single file
- adding image support through url_for to support 3rd party cloud storage
- use html 5 video element for video files
- use html audio element for audio files
- download link to other files
- preview videos
- preview pdfs
- upload multiple files
- find a way to delete attachments
- preview office files as pictures
-
contributers are welcome (code, suggestions, and bugs).
-
please document your code.
-
add your name to the
contribute.md
.please note that this is my first gem :) i might have gotten some stuff wrong PR's are always welcome
Based on the Administrate::Field::Image template, and inspired by Administrate::Field::Paperclip.