Given there is a user with an attachable avatar:
class User < ApplicationRecord
has_one_attached :avatar
end
If you want to add a preprocessed version follow these steps:
- Add the named version and deploy
class User < ApplicationRecord
has_one_attached :avatar do |attachable|
attachable.variant :preview, resize_to_fit: [177, 177 * 9 / 16], preprocessed: true
end
end
- Preprocess this version for all existing records
bundle exec rails runner 'User.find_each { |user| user.avatar.variant(:picker).processed }'
- Use the new variant and deploy
Posted by Emanuel to makandra dev (2025-02-24 15:41)