开发者

Polymorphic Paperclip Interpolations

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜