Text
paperclip 2.3.1.1 validates_attachment_presence gotcha
today I had a paperclip validation error:
/vendor/gems/paperclip-2.3.1.1/lib/paperclip.rb:284:in `validates_attachment_presence’: You have a nil object when you didn’t expect it! (NoMethodError)
but the image was there, and I really didn’t get what the problem was.
I am glad I commented it out and worked on something else. After a bit I had a second look and I found out the validation was set before the has_attached_file.
Make sure of the following order have:
- has_attached_file :hero_image
- validates_attachment_presence :hero_image