# Validates\_presence\_of

**URL:** <https://www.ruby-forum.com/t/validates-presence-of/138838>\
**Category:** Rails\
**Created:** [May 28, 2008, 7:49am UTC](https://www.ruby-forum.com/t/validates-presence-of/138838 "2008-05-28T07:49:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![asetzler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@asetzler](https://www.ruby-forum.com/u/asetzler)\
**Post date:** [May 28, 2008, 7:49am UTC](https://www.ruby-forum.com/t/validates-presence-of/138838/1 "2008-05-28T07:49:08Z")

</div>

Hi everyone,

I am a total novice with Ruby on Rails and I’m having a problem using  
validates\_presence\_of. I’m following a tutorial from a book called  
“Ruby on rails: up and running” and I’m not getting the result I expect  
(and what the book expects).

Here’s my model:  
class Photo \< ActiveRecord::Base  
validates\_presence\_of :filename  
end

I tested this using rails console:

> > photo=Photo.new  
> > =\> #\<Photo id: nil, filename: nil\>
> 
> > photo.save  
> > =\> true
> 
> > puts photo.filename  
> > nil

I expect (and so does the book) that photo.save returns false and  
nothing is saved to the database, but it saves anyway. Any ideas what I  
am doing wrong? Forgive me if it’s something ridiculously simple that  
I’ve overlooked, it is quite late 😉  
If you could point me in the right direction I would be greatly  
appreciative.

Cheers,  
Adam
