From 596cd8317b9917941f90a8643d54335f7406b8b3 Mon Sep 17 00:00:00 2001 From: CassioMarques Date: Sat, 13 Dec 2008 21:22:34 -0200 Subject: Some more info about the effect of calling the clear method upon a model's errors collection (AR Validations an Callbacks Guide) --- .../doc/guides/html/activerecord_validations_callbacks.html | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'railties/doc/guides/html') diff --git a/railties/doc/guides/html/activerecord_validations_callbacks.html b/railties/doc/guides/html/activerecord_validations_callbacks.html index 75c0f26a45..27f6c51d4f 100644 --- a/railties/doc/guides/html/activerecord_validations_callbacks.html +++ b/railties/doc/guides/html/activerecord_validations_callbacks.html @@ -405,7 +405,7 @@ http://www.gnu.org/software/src-highlite --> >> p.new_record? => false -

Saving new records means sending an SQL insert operation to the database, while saving existing records (by calling either save or update_attributes) will result in a SQL update operation. Active Record will use this facts to perform validations upon your objects, avoiding then to be recorded to the database if their inner state is invalid in some way. You can specify validations that will be beformed every time a object is saved, just when you're creating a new record or when you're updating an existing one.

+

Saving new records means sending an SQL insert operation to the database, while saving existing records (by calling either save or update_attributes) will result in a SQL update operation. Active Record will use these facts to perform validations upon your objects, avoiding then to be recorded to the database if their inner state is invalid in some way. You can specify validations that will be beformed every time a object is saved, just when you're creating a new record or when you're updating an existing one.

@@ -899,7 +899,7 @@ person.errors.<
  • -clear is used when you intentionally wants to clear all the messages in the errors collection. +clear is used when you intentionally want to clear all the messages in the errors collection. However, calling errors.clear upon an invalid object won't make it valid: the errors collection will now be empty, but the next time you call valid? or any method that tries to save this object to the database, the validations will run. If any of them fails, the errors collection will get filled again.

@@ -914,12 +914,15 @@ http://www.gnu.org/software/src-highlite --> end person = Person.new -puts person.valid? # => false +person.valid? # => false person.errors.on(:name) # => ["can't be blank", "is too short (minimum is 3 characters)"] person.errors.clear -person.errors # => nil +person.errors.empty? # => true +p.save # => false +p.errors.on(:name) +# => ["can't be blank", "is too short (minimum is 3 characters)"]

8. Callbacks

-- cgit v1.2.3