Geo*_*e C 8 ruby-on-rails paperclip
上传文件后,是否可以在保存模型之前打开该文件?
我正在使用Paperclip将文件保存在/ public文件夹中.
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
Run Code Online (Sandbox Code Playgroud)
Geo*_*e C 17
找到了:
def model_method
f = open(self.upload.queued_for_write[:original].url)
end
Run Code Online (Sandbox Code Playgroud)
更新:
根据生态学的反应,使用.path而不是.url更新版本的Paperclip宝石
足够接近,但.url对我不起作用,path工作.
file = open(uploaded.queued_for_write[:original].path)
Run Code Online (Sandbox Code Playgroud)
做了伎俩.