You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adam Jahn edited this page Apr 14, 2017
·
12 revisions
If you want to hold both images and regular files as attachments to a model, additional processing (i.e. creating a thumbnail) can be attached only to images.
Here's the example code to create thumbnails when the uploaded file is an image:
If you'll use content_type method make sure to include the MimeTypes module:
classAttachmentUploader < CarrierWave::Uploader::Base# include CarrierWave::MimeTypes# ^ Include MimeTypes for CarrierWave versions < 1.0.0# Call methodprocess:set_content_typeend
Just a mention, to avoid multiple checking if it is needless in your case, you could make it like as:
your_model.rb:
attr_accessor:is_thumbnable
your_uploader.rb:
defimage?(new_file)returnmodel.is_thumbnableunlessmodel.is_thumbnable.nil?model.is_thumbnable= \
begin#your condition goes here and it should return true or false, except nilendend