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
wangpeile edited this page May 9, 2013
·
11 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:
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