Noz Noz - 2 months ago 22
Ruby Question

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' ]


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?


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']}