Rails Filters Order

ruby_on_rails_logoRails has some nice filters for DRYing up repeated actions like creating a activation_code on signup, or an unsubscribe_code, reset code.

before_validation_on_update
before_validation_on_create
validate
validate_on_update
validate_on_create
after_validation
after_validation_on_update
after_validation_on_create
before_save
before_update
before_create
after_update
after_create
after_save

There are many different times when you will want to use these and knowing the order will help a lot in terms of unnessacry debugging.  Like I did today!

Just to note that update and create validation does not depend on which method you call on your model, it is in regard to the state of that model.  So if it is a new model it is create, if the model already exists in database you are doing update.  Keep that in mind!

Posted on September 24, 2009 at 12:23 pm by Jordan Carter · Permalink
In: Uncategorized · Tagged with: , ,

Leave a Reply