質問編集履歴
1
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -34,4 +34,62 @@
|
|
34
34
|
|
35
35
|
end
|
36
36
|
|
37
|
+
```
|
38
|
+
```uploader
|
39
|
+
class StudentLicenseUploader < CarrierWave::Uploader::Base
|
40
|
+
# Include RMagick or MiniMagick support:
|
41
|
+
# include CarrierWave::RMagick
|
42
|
+
include CarrierWave::MiniMagick
|
43
|
+
|
44
|
+
# Choose what kind of storage to use for this uploader:
|
45
|
+
if Rails.env.development?
|
46
|
+
storage :file
|
47
|
+
elsif Rails.env.test?
|
48
|
+
storage :file
|
49
|
+
else
|
50
|
+
storage :fog
|
51
|
+
end
|
52
|
+
# storage :fog
|
53
|
+
|
54
|
+
# Override the directory where uploaded files will be stored.
|
55
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
56
|
+
def store_dir
|
57
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
58
|
+
end
|
59
|
+
|
60
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
61
|
+
# def default_url(*args)
|
62
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
63
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
64
|
+
#
|
65
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
66
|
+
# end
|
67
|
+
process resize_to_fit: [300, 300]
|
68
|
+
# Process files as they are uploaded:
|
69
|
+
# process scale: [200, 300]
|
70
|
+
#
|
71
|
+
# def scale(width, height)
|
72
|
+
# # do something
|
73
|
+
# end
|
74
|
+
process :convert => 'jpg'
|
75
|
+
# Create different versions of your uploaded files:
|
76
|
+
# version :thumb do
|
77
|
+
# process resize_to_fit: [50, 50]
|
78
|
+
# end
|
79
|
+
version :thumb do
|
80
|
+
process resize_to_fit: [300, 300]
|
81
|
+
end
|
82
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
83
|
+
# For images you might use something like this:
|
84
|
+
# def extension_whitelist
|
85
|
+
# %w(jpg jpeg gif png)
|
86
|
+
# end
|
87
|
+
|
88
|
+
# Override the filename of the uploaded files:
|
89
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
90
|
+
def filename
|
91
|
+
super.chomp(File.extname(super))+'jpg' if original_filename.present?
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
37
95
|
```
|