Nil Reference when Update
-
12-09-2019 - |
Question
I am trying to get Paperclip working with MiniExiftool.
I finally wrote this:
# 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
I get:
Mysql::Error: Column 'user_id' cannot be null ...
Without save! all works well, but self.date remains null (even if exif['date_time_original'] is NOT null).
I am really frustrated. How can I get Paperclip working with MiniExiftool?
Solution
Not sure, but you might check whether exif['date_time_original'] is giving you a date, or a string, and if it is a string, whether it can be parsed properly.
you also might try using
update_attribute(:date, exif['date_time_original'])
in place of
self.date = exif['date_time_original']
save!
That will bypass validation, and just save the updated attribute.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow