开发者

Polymorphic Paperclip Interpolations

开发者 https://www.devze.com 2023-01-02 18:42 出处:网络
I\'m using the Polymorphic fork of Paperclip in Rails, but have been having some massive problems with regards to the overwriting of unique filenames. No matter whether I put a time-stamp (more on tha

I'm using the Polymorphic fork of Paperclip in Rails, but have been having some massive problems with regards to the overwriting of unique filenames. No matter whether I put a time-stamp (more on that in a second) or the id of the asset in the URL, if a file with the same name is uploaded subsequently, then the previous one is overwritten.

Also, it was working before, but the Time interpolation is now outputting just "0" instead of the timestamp.

module Paperclip
  module Interpolations
    def stamp(attachment, style)
      attachment.instance_read(:created_at).to_i
    end
  end
end

Now just outputs;

0

This is what my URL field is;

:url => "/assets/ima开发者_StackOverflow社区ges/:stamp/:id_:style.:extension"

Thanks.


Try adding this to config/initializers/paperclip.rb

Paperclip.interpolates :stamp do |attachment, style|
  attachment.created_at.to_i
end
0

精彩评论

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