代码之家  ›  专栏  ›  技术社区  ›  morgan freeman

回形针:丢弃“如果”功能

  •  0
  • morgan freeman  · 技术社区  · 16 年前

    我用的是回形针,接受的属性是。我想知道如果照片有{model}\u file\u size==nil,那么丢弃照片(即不保存在db中)的最佳方法是什么。这可以使用属性\u fu来完成,就像下面的示例中那样,使用discard \u if选项。摄影课使用回形针。但是,我不想使用属性u-fu。

    class Stadium 
      has_many :photos, :as => :parent, :discard_if => proc { |upload| upload.photo_file_size.nil? } # discard_if does not work
      accepts_nested_attributes_for :photos
    end
    

    非常感谢。

    1 回复  |  直到 16 年前
        1
  •  0
  •   dangerousdave    16 年前

    回形针提供了一个validates\u附件\u大小验证,我想这会达到什么效果,请看自述 http://github.com/thoughtbot/paperclip

    此外,这个链接可能会引起兴趣。

    http://shiningthrough.co.uk/Dynamic-multiple-image-uploads-with-Ruby-on-Rails