質問編集履歴
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -71,3 +71,119 @@
|
|
71
71
|
|
72
72
|
|
73
73
|
```
|
74
|
+
|
75
|
+
```uploader
|
76
|
+
|
77
|
+
class StudentLicenseUploader < CarrierWave::Uploader::Base
|
78
|
+
|
79
|
+
# Include RMagick or MiniMagick support:
|
80
|
+
|
81
|
+
# include CarrierWave::RMagick
|
82
|
+
|
83
|
+
include CarrierWave::MiniMagick
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
# Choose what kind of storage to use for this uploader:
|
88
|
+
|
89
|
+
if Rails.env.development?
|
90
|
+
|
91
|
+
storage :file
|
92
|
+
|
93
|
+
elsif Rails.env.test?
|
94
|
+
|
95
|
+
storage :file
|
96
|
+
|
97
|
+
else
|
98
|
+
|
99
|
+
storage :fog
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
# storage :fog
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
# Override the directory where uploaded files will be stored.
|
108
|
+
|
109
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
110
|
+
|
111
|
+
def store_dir
|
112
|
+
|
113
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
120
|
+
|
121
|
+
# def default_url(*args)
|
122
|
+
|
123
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
124
|
+
|
125
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
126
|
+
|
127
|
+
#
|
128
|
+
|
129
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
130
|
+
|
131
|
+
# end
|
132
|
+
|
133
|
+
process resize_to_fit: [300, 300]
|
134
|
+
|
135
|
+
# Process files as they are uploaded:
|
136
|
+
|
137
|
+
# process scale: [200, 300]
|
138
|
+
|
139
|
+
#
|
140
|
+
|
141
|
+
# def scale(width, height)
|
142
|
+
|
143
|
+
# # do something
|
144
|
+
|
145
|
+
# end
|
146
|
+
|
147
|
+
process :convert => 'jpg'
|
148
|
+
|
149
|
+
# Create different versions of your uploaded files:
|
150
|
+
|
151
|
+
# version :thumb do
|
152
|
+
|
153
|
+
# process resize_to_fit: [50, 50]
|
154
|
+
|
155
|
+
# end
|
156
|
+
|
157
|
+
version :thumb do
|
158
|
+
|
159
|
+
process resize_to_fit: [300, 300]
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
164
|
+
|
165
|
+
# For images you might use something like this:
|
166
|
+
|
167
|
+
# def extension_whitelist
|
168
|
+
|
169
|
+
# %w(jpg jpeg gif png)
|
170
|
+
|
171
|
+
# end
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
# Override the filename of the uploaded files:
|
176
|
+
|
177
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
178
|
+
|
179
|
+
def filename
|
180
|
+
|
181
|
+
super.chomp(File.extname(super))+'jpg' if original_filename.present?
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
```
|