# Validation without saving

**URL:** <https://www.ruby-forum.com/t/validation-without-saving/121364>\
**Category:** Rails\
**Created:** [November 27, 2007, 10:05am UTC](https://www.ruby-forum.com/t/validation-without-saving/121364 "2007-11-27T10:05:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 27, 2007, 10:05am UTC](https://www.ruby-forum.com/t/validation-without-saving/121364/1 "2007-11-27T10:05:32Z")

</div>

One of the things that strikes me as odd about the validations as I  
understand them to work from AWDWR, is that the validations  
themselves are only triggered upon a save.

I brought this up earlier that I am accustomed to doing validations  
of data before updating a model with it, but Rails wants to allow the  
modification of the model, then only bother to validate it if it is  
saved – at least that’s what I’m seeing at this point.

What good does that do unsaved model data? Model data that perhaps  
never gets saved to a database, but nonetheless must have validated  
data to perform its interim purpose.

What if I bring data in from a web service or a file – isn’t it best  
to complain to that source (or log the problem, or whatever) at the  
moment the data is accepted, and not some who-knows-when point which  
may be tainted by some other process and therefore I lose the ability  
to complain to the actual source that provided the bad data?

Looking at the methods in validations.rb, I’m not seeing a method  
that gives me arbitrary control over when to invoke validations.

I’m probably still not seeing the whole picture, but I’m getting that  
“something’s wrong” feeling.

– gw (www.railsdev.ws)

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 27, 2007, 3:29pm UTC](https://www.ruby-forum.com/t/validation-without-saving/121364/2 "2007-11-27T15:29:32Z")

</div>

if you create a validate function, which automatically gets called by  
rails you can do

my\_object.validate

there are 2 others validate\_on\_create and validate\_on\_update

the my\_object.valid? method should invoke these and any of the  
validates\_X functions

and if you want something that is unique to this data and that doesn’t  
get saved on create your own method  
and call my\_object.my\_method\_name

White W.

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 27, 2007, 10:23am UTC](https://www.ruby-forum.com/t/validation-without-saving/121364/3 "2007-11-27T10:23:43Z")

</div>

On 11/27/07, Greg W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What good does that do unsaved model data? Model data that perhaps  
> that gives me arbitrary control over when to invoke validations.
> 
> >

my\_object.valid?
