我正在尝试让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: Column 'user_id' cannot be null ...
没有保存!一切正常,但self.date保持为null(即使exif ['date_time_original']为非null)。
我真的很沮丧。如何让Paperclip使用MiniExiftool?
答案 0 :(得分:0)
不确定,但你可能会检查是否exif ['date_time_original'] 给你一个日期或一个字符串,如果它是一个字符串,它是否可以正确解析。
您也可以尝试使用
update_attribute(:date, exif['date_time_original'])
取代
self.date = exif['date_time_original']
save!
这将绕过验证,只保存更新的属性。