[英]paperclip - modify the path structure for storing images
I would be really grateful if someone could help me with this. 如果有人可以帮助我,我将非常感激。
I am using paperclip to upload images. 我正在使用回形针上传图像。
I modified my paperclip.rb to add the following interpolation code: 我修改了paperclip.rb以添加以下插值代码:
Paperclip.interpolates :submission_id do |attachment, style|
attachment.instance.submission_id
end
I have the following code included in the image.rb: 我在image.rb中包含以下代码:
has_attached_file :data, :path => ":rails_root/public/system/datas/:submission_id/:id/:style",
:url => "/system/datas/:submission_id/:id/:style",
:styles => {
:thumb => "50x50#",
:large => "640x480#"
}
Currently, when i upload images, they are stored in the following folder structure: 当前,当我上传图像时,它们存储在以下文件夹结构中:
submission_id/image_primary_id/image -----> 13/244/original subscription_id / image_primary_id / image -----> 13/244 /原始
I would like to store the image in the following format: SUB_submission_id/originals/imagename.jpeg ---> SUB_13/originals/image01.jpeg 我想以以下格式存储图像:SUB_submission_id / originals / imagename.jpeg ---> SUB_13 / originals / image01.jpeg
Please could someone shed some light on this how to do this. 请有人对此有所帮助。
Thanks a lot for your help 非常感谢你的帮助
Did you try something like this? 你尝试过这样的事情吗?
Paperclip.interpolates :submission_id do |attachment, style|
"SUB_#{attachment.instance.submission_id}"
end
And the drop the :id from the path and url (make sure you don't upload files with the same name though) 然后从路径和网址中删除:id(不过请确保不要上传具有相同名称的文件)
has_attached_file :data, :path => ":rails_root/public/system/datas/:submission_id/:style",
:url => "/system/datas/:submission_id/:style",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.