开发者

paperclip - modify the path structure for storing images

I would be really grateful if someone coul开发者_JAVA百科d help me with this.

I am using paperclip to upload images.

I modified my paperclip.rb to add the following interpolation code:

 Paperclip.interpolates :submission_id do |attachment, style|
  attachment.instance.submission_id 
  end

I have the following code included in the 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

I would like to store the image in the following format: 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)

has_attached_file :data, :path => ":rails_root/public/system/datas/:submission_id/:style",
                         :url => "/system/datas/:submission_id/:style",
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜