【问题标题】:Polymorphic Paperclip Interpolations多态回形针插值
【发布时间】:2010-06-07 11:50:15
【问题描述】:

我在 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"

谢谢。

【问题讨论】:

    标签: ruby-on-rails ruby paperclip interpolation polymorphism


    【解决方案1】:

    尝试将其添加到 config/initializers/paperclip.rb

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多