# Difference between validate and validate\_on\_create

**URL:** <https://www.ruby-forum.com/t/difference-between-validate-and-validate-on-create/206355>\
**Category:** RSpec\
**Created:** [April 28, 2011, 9:06pm UTC](https://www.ruby-forum.com/t/difference-between-validate-and-validate-on-create/206355 "2011-04-28T21:06:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 28, 2011, 9:06pm UTC](https://www.ruby-forum.com/t/difference-between-validate-and-validate-on-create/206355/1 "2011-04-28T21:06:41Z")

</div>

i just ran into a problem with some test, and i am not exactly sure why,  
but the difference happened when i changed my model validation from:

validate :custom\_validation

to:

validate\_on\_create :custom\_validation

can someone give me any ideas on where in the chain the validation takes  
place?

thanks!

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [April 28, 2011, 10:00pm UTC](https://www.ruby-forum.com/t/difference-between-validate-and-validate-on-create/206355/2 "2011-04-28T22:00:38Z")

</div>

On Thu, Apr 28, 2011 at 3:06 PM, Sergio R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> place?  
> This is really a Rails or ActiveRecord question rather than RSpec.

In any case.

validate :custom\_validation  
will run the custom\_validation method whether the model is being  
created or updated.

validate\_on\_create :custom\_validation  
will only run the custom\_validation method when the method is being  
created.

There’s also a validate\_on\_update method which will run the custom  
validation method when the model is being updated but not when it is  
created.

## [http://guides.rubyonrails.org/active\_record\_validations\_callbacks.html#creating-custom-validation-methods](http://guides.rubyonrails.org/active_record_validations_callbacks.html#creating-custom-validation-methods)

Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Github: [rubyredrick (Rick DeNatale) · GitHub](http://github.com/rubyredrick)  
Twitter: @RickDeNatale  
WWR: [NameBright - Coming Soon](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [April 28, 2011, 10:35pm UTC](https://www.ruby-forum.com/t/difference-between-validate-and-validate-on-create/206355/3 "2011-04-28T22:35:54Z")

</div>

thanks, nick… i looks like i need to hunt around a bit more as to what  
was causing my problem…

thanks!

---

<div class="post-metadata">

**Author:** ![spacechurro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@spacechurro](https://www.ruby-forum.com/u/spacechurro)\
**Post date:** [April 28, 2011, 10:54pm UTC](https://www.ruby-forum.com/t/difference-between-validate-and-validate-on-create/206355/4 "2011-04-28T22:54:23Z")

</div>

On Thu, Apr 28, 2011 at 2:06 PM, Sergio R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> place?
> 
> thanks!
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> rspec-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/rspec-users](http://rubyforge.org/mailman/listinfo/rspec-users)

`validate` will run that validation on create _and_ update.  
`validate_on_create` will only run on creation.
