質問編集履歴

1

image_uploader.rb 追記

2020/06/25 23:44

投稿

TaaShii
TaaShii

スコア5

test CHANGED
File without changes
test CHANGED
@@ -216,6 +216,108 @@
216
216
 
217
217
  ```
218
218
 
219
+
220
+
221
+ ### image_uploader.rb
222
+
223
+ ```ruby
224
+
225
+ class ImageUploader < CarrierWave::Uploader::Base
226
+
227
+ # Include RMagick or MiniMagick support:
228
+
229
+ # include CarrierWave::RMagick
230
+
231
+ include CarrierWave::MiniMagick
232
+
233
+
234
+
235
+ # Choose what kind of storage to use for this uploader:
236
+
237
+ storage :file
238
+
239
+ # storage :fog
240
+
241
+
242
+
243
+ # Override the directory where uploaded files will be stored.
244
+
245
+ # This is a sensible default for uploaders that are meant to be mounted:
246
+
247
+ def store_dir
248
+
249
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
250
+
251
+ end
252
+
253
+
254
+
255
+ # Provide a default URL as a default if there hasn't been a file uploaded:
256
+
257
+ # def default_url(*args)
258
+
259
+ # # For Rails 3.1+ asset pipeline compatibility:
260
+
261
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
262
+
263
+ #
264
+
265
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
266
+
267
+ # end
268
+
269
+
270
+
271
+ # Process files as they are uploaded:
272
+
273
+ # process scale: [200, 300]
274
+
275
+ #
276
+
277
+ # def scale(width, height)
278
+
279
+ # # do something
280
+
281
+ # end
282
+
283
+
284
+
285
+ # Create different versions of your uploaded files:
286
+
287
+ # version :thumb do
288
+
289
+ # process resize_to_fit: [50, 50]
290
+
291
+ # end
292
+
293
+
294
+
295
+ # Add a white list of extensions which are allowed to be uploaded.
296
+
297
+ # For images you might use something like this:
298
+
299
+ # def extension_whitelist
300
+
301
+ # %w(jpg jpeg gif png)
302
+
303
+ # end
304
+
305
+
306
+
307
+ # Override the filename of the uploaded files:
308
+
309
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
310
+
311
+ # def filename
312
+
313
+ # "something.jpg" if original_filename
314
+
315
+ # end
316
+
317
+ end
318
+
319
+ ```
320
+
219
321
  ご有識のある方、ご助力お願いします。
220
322
 
221
323
  蛇足な記述等あればそちらもご指摘いただけると幸いです。