BetterStorage
- Prefix ActiveStorage uploads with
devand customized datetime format. - Protect production files from deletion in development environment.
public_urlmethod for ActiveStorage attachments and blobs.
Usage
# better_storage.rb initializer
BetterStorage.configure do |config|
config.protect_production_files = true # default: Rails.env.development?
config.prefix_date_format = "%Y/%m/%d" # default: "%Y%m"
end
class User < ApplicationRecord
has_one_attached :avatar do |attachable|
attachable.variant :thumb, resize_to_limit: [120, 120]
end
end
user = User.first
user.avatar.public_url
user.avatar.public_url(:thumb)
Installation
Add this line to your application's Gemfile:
gem "better_storage"
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.