picture_uploader.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. class PictureUploader < CarrierWave::Uploader::Base
  2. # Include MiniMagick support:
  3. include CarrierWave::MiniMagick
  4. process resize_to_limit: [400, 400]
  5. # Choose what kind of storage to use for this uploader:
  6. storage :file
  7. # Override the directory where uploaded files will be stored.
  8. # This is a sensible default for uploaders that are meant to be mounted:
  9. def store_dir
  10. "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  11. end
  12. # Provide a default URL as a default if there hasn't been a file uploaded:
  13. def default_url(*args)
  14. "/images/fallback/" + [version_name, "default_profile.png"].compact.join('_')
  15. end
  16. # Create different versions of your uploaded files:
  17. version :tiny do
  18. process resize_to_fit: [20, 20]
  19. end
  20. version :small do
  21. process resize_to_fit: [50, 50]
  22. end
  23. version :medium do
  24. process resize_to_fit: [100, 100]
  25. end
  26. # Add a white list of extensions which are allowed to be uploaded.
  27. # For images you might use something like this:
  28. def extension_whitelist
  29. %w(jpg jpeg gif png)
  30. end
  31. # Override the filename of the uploaded files:
  32. # Avoid using model.id or version_name here, see uploader/store.rb for details.
  33. # def filename
  34. # "something.jpg" if original_filename
  35. # end
  36. end