多态回形针插值
我在 Rails 中使用 Paperclip 的多态分支,但在覆盖唯一文件名方面遇到了一些大问题。无论我是否在 URL 中添加时间戳(稍后详细介绍)或资产的 id,如果随后上传同名文件,则前一个文件将被覆盖。
此外,它之前可以工作,但时间插值现在仅输出“0”而不是时间戳。
module Paperclip
module Interpolations
def stamp(attachment, style)
attachment.instance_read(:created_at).to_i
end
end
end
现在只是输出;
0
这就是我的 URL 字段;
:url => "/assets/images/:stamp/:id_:style.:extension"
谢谢。
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/images/:stamp/:id_:style.:extension"
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将其添加到 config/initializers/paperclip.rb
Try adding this to config/initializers/paperclip.rb