【问题标题】:Paperclip: specify attachment fields in post_process callbacks回形针:在 post_process 回调中指定附件字段
【发布时间】:2015-01-26 23:12:05
【问题描述】:

我有一个看起来像这样的模型:

class Attachment < ActiveRecord::Base
  has_attached_file :foo
  has_attached_file :bar
end

我想指定一个before_post_process 回调,它基本上会根据某些条件跳过后期处理,但仅适用于:bar 字段

文档表明我可以添加:

before_post_process :skip_for_audio

但此回调将同时为 :foo:bar 运行。

我该如何进行这项工作?

【问题讨论】:

    标签: ruby-on-rails-4 paperclip


    【解决方案1】:

    根据 Paperclip documentation,您应该可以使用 before_bar_post_process 回调,如果您返回 false,则 bar 的后处理将停止:

    class Attachment < ActiveRecord::Base
    
        has_attached_file :foo
        has_attached_file :bar
    
        before_bar_post_process check_bar_condition
    
        def check_bar_condition
            ...
            return false if #some_condition_fails
            ...
        end
    end
    

    【讨论】:

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