# Validates\_presence\_of file fields

**URL:** <https://www.ruby-forum.com/t/validates-presence-of-file-fields/179968>\
**Category:** Rails\
**Created:** [December 8, 2009, 10:12pm UTC](https://www.ruby-forum.com/t/validates-presence-of-file-fields/179968 "2009-12-08T22:12:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tabassman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tabassman](https://www.ruby-forum.com/u/tabassman)\
**Post date:** [December 8, 2009, 10:12pm UTC](https://www.ruby-forum.com/t/validates-presence-of-file-fields/179968/1 "2009-12-08T22:12:22Z")

</div>

I can’t seem to get validates\_presence\_of to work with file fields. It  
keeps on reporting the field is empty whether I put a file in or not. Is  
there a way to validate whether a file has been uploaded?

---

<div class="post-metadata">

**Author:** ![tabassman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tabassman](https://www.ruby-forum.com/u/tabassman)\
**Post date:** [December 9, 2009, 11:51am UTC](https://www.ruby-forum.com/t/validates-presence-of-file-fields/179968/2 "2009-12-09T11:51:31Z")

</div>

Victor T. wrote:

> I can’t seem to get validates\_presence\_of to work with file fields. It  
> keeps on reporting the field is empty whether I put a file in or not. Is  
> there a way to validate whether a file has been uploaded?

What is your database structure in relation to the file field?

---

<div class="post-metadata">

**Author:** ![tabassman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tabassman](https://www.ruby-forum.com/u/tabassman)\
**Post date:** [December 9, 2009, 2:45pm UTC](https://www.ruby-forum.com/t/validates-presence-of-file-fields/179968/3 "2009-12-09T14:45:35Z")

</div>

There is a varchar field I put in by mistake, but I’m not storing  
anything in it. Can that be causing the problem?

Pale H. wrote:

> Victor T. wrote:
> 
> > I can’t seem to get validates\_presence\_of to work with file fields. It  
> > keeps on reporting the field is empty whether I put a file in or not. Is  
> > there a way to validate whether a file has been uploaded?
> 
> What is your database structure in relation to the file field?

---

<div class="post-metadata">

**Author:** ![tabassman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tabassman](https://www.ruby-forum.com/u/tabassman)\
**Post date:** [December 9, 2009, 3:17pm UTC](https://www.ruby-forum.com/t/validates-presence-of-file-fields/179968/4 "2009-12-09T15:17:36Z")

</div>

Victor T. wrote:

> There is a varchar field I put in by mistake, but I’m not storing  
> anything in it. Can that be causing the problem?
> 
> Pale H. wrote:
> 
> > Victor T. wrote:
> > 
> > > I can’t seem to get validates\_presence\_of to work with file fields. It  
> > > keeps on reporting the field is empty whether I put a file in or not. Is  
> > > there a way to validate whether a file has been uploaded?
> > 
> > What is your database structure in relation to the file field?

No, that shouldn’t be causing the problem. Is it possible you can show  
us the code in relation to your problem?

---

<div class="post-metadata">

**Author:** ![tabassman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tabassman](https://www.ruby-forum.com/u/tabassman)\
**Post date:** [December 9, 2009, 4:00pm UTC](https://www.ruby-forum.com/t/validates-presence-of-file-fields/179968/5 "2009-12-09T16:00:51Z")

</div>

Victor T. wrote:

> There is a varchar field I put in by mistake, but I’m not storing  
> anything in it. Can that be causing the problem?
> 
> Pale H. wrote:
> 
> > Victor T. wrote:
> > 
> > > I can’t seem to get validates\_presence\_of to work with file fields. It  
> > > keeps on reporting the field is empty whether I put a file in or not. Is  
> > > there a way to validate whether a file has been uploaded?
> > 
> > What is your database structure in relation to the file field?

Ah I just realised. Could the problem be I’m using form\_remote\_for?

---

<div class="post-metadata">

**Author:** ![tabassman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tabassman](https://www.ruby-forum.com/u/tabassman)\
**Post date:** [December 9, 2009, 4:25pm UTC](https://www.ruby-forum.com/t/validates-presence-of-file-fields/179968/6 "2009-12-09T16:25:41Z")

</div>

Victor T. wrote:

> Victor T. wrote:
> 
> > There is a varchar field I put in by mistake, but I’m not storing  
> > anything in it. Can that be causing the problem?
> > 
> > Pale H. wrote:
> > 
> > > Victor T. wrote:
> > > 
> > > > I can’t seem to get validates\_presence\_of to work with file fields. It  
> > > > keeps on reporting the field is empty whether I put a file in or not. Is  
> > > > there a way to validate whether a file has been uploaded?
> > > 
> > > What is your database structure in relation to the file field?
> 
> Ah I just realised. Could the problem be I’m using form\_remote\_for?

Try using something along the lines of:

\<% remote\_form\_for(@class\_name) do |f| %\>  
…  
\<% end %\>
