# Validation in attachment\_fu

**URL:** <https://www.ruby-forum.com/t/validation-in-attachment-fu/179648>\
**Category:** Rails\
**Created:** [December 1, 2009, 7:42am UTC](https://www.ruby-forum.com/t/validation-in-attachment-fu/179648 "2009-12-01T07:42:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![srikanth\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@srikanth\_j](https://www.ruby-forum.com/u/srikanth_j)\
**Post date:** [December 1, 2009, 7:42am UTC](https://www.ruby-forum.com/t/validation-in-attachment-fu/179648/1 "2009-12-01T07:42:53Z")

</div>

Hi,

I have a doubt that how to validate in attachment\_fu when 2 different  
file formats(Image/Document) are used.

I have a model named Image, Documents ,

class Images \< ActiveRecord::Base  
has\_many :attachments, :as =\> :parent  
end

class Documents \< ActiveRecord::Base  
has\_many :attachments, :as =\> :parent  
end

class Attachments \< ActiveRecord::Base  
belongs\_to :parent, :polymorphic =\> true  
has\_attachment :storage =\> :file\_system,  
:path\_prefix =\> ‘public/attachments’,  
:size =\> 0.kilobytes…5000.kilobytes,  
:max\_size =\> 5000.kilobytes,  
:content\_type =\>  
[‘application/pdf’,‘application/vnd.openxmlformats-officedocument.presentationml.presentation’,‘application/vnd.ms-powerpoint’,  
‘application/msword’, ‘text/plain’,:image]

validates\_as\_attachment  
end

I am uploading Image from the a view file, validation should be made  
only for the Image. Please help how can i make the validation for image  
& document seperately.

---

<div class="post-metadata">

**Author:** ![srikanth\_j](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a5b964/32.png) [@srikanth\_j](https://www.ruby-forum.com/u/srikanth_j)\
**Post date:** [December 1, 2009, 7:46am UTC](https://www.ruby-forum.com/t/validation-in-attachment-fu/179648/2 "2009-12-01T07:46:33Z")

</div>

& When I am Uploading a Document from another view file, Validation  
should be done only for documents.

Please tell me how to validate individually for images & Documents.

Thanks,  
Srikanth J
