Advertisement
YarikHrom

Untitled

Mar 24th, 2022
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.20 KB | None | 0 0
  1. # frozen_string_literal: true
  2.  
  3. class AvatarUploader < CarrierWave::Uploader::Base
  4.   # Include RMagick or MiniMagick support:
  5.   # include CarrierWave::RMagick
  6.   include CarrierWave::MiniMagick
  7.  
  8.   def extension_whitelist
  9.     %w[jpg jpeg gif png]
  10.   end
  11.  
  12.   # Override the directory where uploaded files will be stored.
  13.   # This is a sensible default for uploaders that are meant to be mounted:
  14.   def store_dir
  15.     "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  16.   end
  17.  
  18.   # Process files as they are uploaded:
  19.   # process scale: [200, 300]
  20.   #
  21.   # def scale(width, height)
  22.   #   # do something
  23.   # end
  24.  
  25.   # Create different versions of your uploaded files:
  26.   version :thumb do
  27.     process resize_to_fit: [50, 50]
  28.   end
  29.  
  30.   version :profile do
  31.     process resize_to_fit: [400, 400]
  32.   end
  33.  
  34.   # Add a white list of extensions which are allowed to be uploaded.
  35.   # For images you might use something like this:
  36.   # def extension_whitelist
  37.   #   %w(jpg jpeg gif png)
  38.   # end
  39.  
  40.   # Override the filename of the uploaded files:
  41.   # Avoid using model.id or version_name here, see uploader/store.rb for details.
  42.   # def filename
  43.   #   "something.jpg" if original_filename
  44.   # end
  45. end
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement