【问题标题】:Nil Reference when Update更新时无参考
【发布时间】:2009-07-10 12:17:36
【问题描述】:

我正在尝试让 Paperclip 与 MiniExiftool 一起使用。

我终于写了这个:


# Photo model

  belongs_to :user

  has_attached_file :picture

  after_picture_post_process :copy_exif_data

private

  def copy_exif_data
    exif = MiniExiftool.new picture.queued_for_write[:original].path
    self.date = exif['date_time_original']

    save!
  end

我明白了:

Mysql::Error: 列 'user_id' 不能为空 ...

没有保存!一切正常,但 self.date 仍然为空(即使 exif['date_time_original'] 不为空)。

我真的很沮丧。如何让 Paperclip 与 MiniExiftool 一起使用?

【问题讨论】:

    标签: ruby-on-rails callback paperclip


    【解决方案1】:

    不确定,但您可以检查 exif['date_time_original'] 是给你一个日期,还是一个字符串,如果是字符串,是否能正确解析。

    你也可以试试

    update_attribute(:date, exif['date_time_original'])
    

    代替

    self.date = exif['date_time_original']
    save!
    

    这将绕过验证,只保存更新的属性。

    【讨论】:

      猜你喜欢
      • 2014-10-16
      • 1970-01-01
      • 2013-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多