Once you've uploaded a file, is it possible to open that file before the model is saved?
I'm using Paperclip to save files in the /public folder.
class Book < ActiveRecord::Base
before_save :open_it
has_attached_file :upload
def open_it
a_file = open(upload.url) # this doesn't work before save ?
# ...
end
end
found it:
def model_method
f = open(self.upload.queued_for_write[:original].url)
end
Update:
Based on response from ecoologic, use .path
instead of .url
for more recent versions of the Paperclip gem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With