File
WARNING
You must manually require activestorage and image_processing gems in your Gemfile.
# Active Storage makes it simple to upload and reference files
gem "activestorage"
# High-level image processing wrapper for libvips and ImageMagick/GraphicsMagick
gem "image_processing"The File field is the fastest way to implement file uploads in a Ruby on Rails app using Active Storage.
Avo will use your application's Active Storage settings with any supported disk services.
field :avatar, as: :file, is_image: trueAuthorization
INFO
Please ensure you have the upload_{FIELD_ID}?, delete_{FIELD_ID}?, and download_{FIELD_ID}? methods set on your model's Pundit policy. Otherwise, the input and download/delete buttons will be hidden.
Related:
Variants
When using the file field to display an image, you can opt to show a processed variant of that image. This can be achieved using the format_using option.
Example:
field :photo,
as: :file,
format_using: -> {
value.variant(resize_to_limit: [150, 150]).processed.image
}Options
-> accept
Instructs the input to accept only a particular file type for that input using the accept option.
field :cover_video, as: :file, accept: "image/*"Default
nil
Possible values
image/*, audio/*, doc/*, or any other types from the spec.
-> direct_upload
If you have large files and don't want to overload the server with uploads, you can use the direct_upload feature, which will upload the file directly to your cloud provider.
field :cover_video, as: :file, direct_upload: trueDefault
false
Possible values
true, false
-> display_filename
Option that specify if the file should have the caption present or not.
field :cover_video, as: :file, display_filename: falseDefault
true
Possible values
true, false
-> link_to_record
Wraps the content into an anchor that links to the resource.
Friendly.rb - Your friendly European Ruby Conference