A website template with lots of features, built with ruby on rails.

avatar_uploader.rb 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # encoding: utf-8
  2. class AvatarUploader < CarrierWave::Uploader::Base
  3. # Include RMagick or MiniMagick support:
  4. # include CarrierWave::RMagick
  5. include CarrierWave::MiniMagick
  6. include CarrierWave::MimeTypes
  7. # Choose what kind of storage to use for this uploader:
  8. if Rails.env.test? or Rails.env.cucumber?
  9. storage :file
  10. end
  11. if Rails.env.development?
  12. storage :file
  13. end
  14. if Rails.env.production?
  15. # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility if using fog:
  16. # include Sprockets::Rails::Helper
  17. include Sprockets::Helpers
  18. storage :fog
  19. end
  20. process :set_content_type
  21. # Override the directory where uploaded files will be stored.
  22. # This is a sensible default for uploaders that are meant to be mounted:
  23. def store_dir
  24. "uploads/#{mounted_as}/#{model.id}"
  25. end
  26. def cache_dir
  27. " ./tmp/uploads/#{mounted_as}/#{model.id}"
  28. end
  29. # Provide a default URL as a default if there hasn't been a file uploaded:
  30. # def default_url
  31. # # For Rails 3.1+ asset pipeline compatibility:
  32. # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
  33. #
  34. # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  35. # end
  36. # Process files as they are uploaded:
  37. # process :scale => [200, 300]
  38. #
  39. # def scale(width, height)
  40. # # do something
  41. # end
  42. # Create different versions of your uploaded files:
  43. version :thumb do
  44. process :resize_to_fit => [50, 50]
  45. end
  46. # Add a white list of extensions which are allowed to be uploaded.
  47. # For images you might use something like this:
  48. # def extension_white_list
  49. # %w(jpg jpeg gif png)
  50. # end
  51. # Override the filename of the uploaded files:
  52. # Avoid using model.id or version_name here, see uploader/store.rb for details.
  53. # def filename
  54. # "something.jpg" if original_filename
  55. # end
  56. end