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

cover_uploader.rb 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # encoding: utf-8
  2. class CoverUploader < 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::Helpers::RailsHelper
  17. include Sprockets::Helpers::IsolatedHelper
  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 => [300, 200]
  45. end
  46. version :mini do
  47. process :resize_to_fit => [150, 100]
  48. end
  49. # Add a white list of extensions which are allowed to be uploaded.
  50. # For images you might use something like this:
  51. # def extension_white_list
  52. # %w(jpg jpeg gif png)
  53. # end
  54. # Override the filename of the uploaded files:
  55. # Avoid using model.id or version_name here, see uploader/store.rb for details.
  56. # def filename
  57. # "something.jpg" if original_filename
  58. # end
  59. end