Reputation: 1364
I have googled/stack overflowed for hours and not found a solution to this problem. I'm wondering if my installation of PaperClip was somehow unsuccessful. I'm trying to validate an image attachment in my models folder:
validates :image, presence: true,
content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif']},
size: { less_than: 5.megabytes }
I have also tried code more similiar to the read me file on github:
validates_attachment :image, :presence => true,
:content_type => { :content_type => 'image/jpeg', 'image/jpg', 'image/png', 'image/gif' },
:size => { less_than: => 5.megabytes }
And I've tried to use individual validations
validates_attachment_presence :image
validates_attachment_content_type :image,:content_type => ['image/jpeg', 'image/jpg', 'image/png', 'image/gif']
validates_attachment_size :image,:less_than => 5.megabytes
I get an error in all cases. Either:
Routing Error
undefined method `before_image_post_process' for #<Class:0x00000101461750>
Try running rake routes for more information on available routes.
Or:
NoMethodError in PinsController#index
undefined method `key?' for nil:NilClass
Upvotes: 13
Views: 5917
Reputation: 179
I keep getting this error each time just because I always forget to rename the image variable the same way (after copying from the snippet):
has_attached_file :avatar...
validates_attachment_content_type :photo, :content_type...
→ Should be also :avatar
instead of :photo
It's a perfect example of how problems may arize when the code is not DRY.
Upvotes: 4
Reputation: 793
savmac's fix worked for me just now. i was having the same problem upon heroku open. the lines in the model had been out of order previously and my app had worked seamlessly for months--dunno what changed. thanks!
Upvotes: 1
Reputation: 442
Do you have has_attached_file :image
in your file?
If so, make sure it is before validates_attachment
.
Upvotes: 34