Administrate::Field::ActiveStorage
Things To Know:
- to preview pdf files you need to install
mupdforPoppler. - to preview video files you need to install
ffmpeg.
How To Use:
Add administrate-field-active_storage to your Gemfile:
gem 'administrate-field-active_storage'
Install:
$ bundle install
has_one_attached:
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.
has_many_attached:
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
url_only
only the following needs to change in order for the field to be url_only
class ModelDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
attachments: Field::ActiveStorage.({url_only: true}),
# ...
}
# ...
end
Things To Do:
- [x] upload single file
- [x] adding image support through url_for to support 3rd party cloud storage
- [x] use html 5 video element for video files
- [x] use html audio element for audio files
- [x] download link to other files
- [x] preview videos
- [x] preview pdfs
- [x] upload multiple files
- [ ] find a way to delete attachments
- [ ] preview office files as pictures
Contribution guide:
- 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.