If you are using carrierwave gem to upload file and you want to add ratio validations for image In the future, we will add more validations
- Validate ratio image by range
class User < ApplicationRecord
mount_uploader :avatar, AvatarUploader
validates :avatar, image: { ratio_range: 1..1 }
end
- avatar is your field def
- ratio_range is a option of validate.
Carrierwave Image Validate uses I18n for error messages For this, add these keys in your translation file:
en:
errors:
messages:
aspect_ratio_is_not: "must have an aspect ratio of %{aspect_ratio}"
aspect_ratio_unknown: "has an unknown aspect ratio"
Add this line to your application's Gemfile:
// require to handle image
gem 'mini_magick', '>= 4.9.5'
// validate
gem 'carrierwave_image_validate'
And then execute
$ bundle
Released under the MIT License. See the LICENSE file for further details.