Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Paperclip undefined method `validates_attachment'?

I'm getting the error message from some validation code I have in my model. My system is using paperclip to attach many files to a help article, and I know I have paperclip installed because I'm able to upload files just not validate them.

Here's my model:

class HelpAttachment < ActiveRecord::Base

  belongs_to :help

  has_attached_file :attachment, 
                    :styles => { :medium => "300x300>",
                                 :thumb => "100x100>" }

  validates_attachment :attachment, :content_type => [ 'image/png', 'image/jpg', 'image/gif', "application/pdf", 
                                    'video/mpeg', 'video/quicktime', 'video/x-ms-asf', 'video/x-msvideo', 
                                    'video/x-flv' ]


end

And this is the error message I get when I try and submit a new attachment:

NoMethodError in HelpsController#create

undefined method `validates_attachment' for #<Class:0x00000005581498>

If I remove the validates_attachment line everything works, just no file validation.

I have gem 'paperclip' in my gemfile and I'm running in development mode.

Any ideas?

like image 769
Noz Avatar asked Jan 31 '26 21:01

Noz


1 Answers

According to the github of paperclip the "new style" validator should look like. This applies to paperclip 3.0 and beyond

validates :attachment, :attachment_content_type => { :content_type => ['image/png', 'image/jpg']}
like image 180
Benjamin Udink ten Cate Avatar answered Feb 02 '26 13:02

Benjamin Udink ten Cate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!