diff options
author | Johann Pardanaud <pardanaud.j@gmail.com> | 2016-02-16 21:50:23 +0300 |
---|---|---|
committer | Johann Pardanaud <pardanaud.j@gmail.com> | 2016-02-16 21:50:23 +0300 |
commit | 78588cfca15348ba062d33061c79df3cfa6b9883 (patch) | |
tree | 39039288941628aab622b0aebdf749d1b51d3349 /app/uploaders | |
parent | 3ca16ec2ecd5d999f60ea9f667428184675c610e (diff) |
Improve user experience for avatar cropping
- Avoid incomprehensible errors on non-integer cropping values
- Set the default cropping area to 80%
Diffstat (limited to 'app/uploaders')
-rw-r--r-- | app/uploaders/avatar_uploader.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/app/uploaders/avatar_uploader.rb b/app/uploaders/avatar_uploader.rb index 239c99e06dc..60ee80cf002 100644 --- a/app/uploaders/avatar_uploader.rb +++ b/app/uploaders/avatar_uploader.rb @@ -10,8 +10,15 @@ class AvatarUploader < CarrierWave::Uploader::Base process :cropper + def is_integer? string + true if Integer(string) rescue false + end + def cropper - if model.instance_of? User + is_compliant = model.kind_of?(User) && is_integer?(model.avatar_crop_size) + is_compliant = is_compliant && is_integer?(model.avatar_crop_x) && is_integer?(model.avatar_crop_y) + + if is_compliant manipulate! do |img| img.crop "#{model.avatar_crop_size}x#{model.avatar_crop_size}+#{model.avatar_crop_x}+#{model.avatar_crop_y}" end |