Jason Pfeifer
2010-Dec-20 00:35 UTC
fork paperclip validations depending on associated model
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.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.