Hi all,
I have a project that is using paperclip to upload and attach files to
associated models. The schema is thus:
Class Project
has_many :attached_files
I want to attach images only (jpg|png|etc) to projects
end
Class Page
has_many :attached_files
I want to attach linked documents (doc|pdf|etc) to pages
end
Class Attachedfile
has attached_file :image
has attached_file :file
end
Right now, I have validations for Project:
validates_attachment_presence :image,
:message => ‘There was no file uploaded!’
validates_attachment_thumbnails :image,
:message => ‘The file you uploaded does not seem to be a valid
image.’
etc…
And now I want to add validations for files attached to pages. Only,
how do I go about only calling the validations for files on Pages, while
only calling validations for Images on Projects? ie. if I add
validations for files on pages it will invalidate the records when I am
saving images on projects.
Does that make sense? The way I know I could work around this is to
have two models: AttachedFile and AttachedImage, but that seems not
necessary and would be an extra database table.