aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-02-04 14:38:45 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-02-04 14:38:45 +0000
commitd39290cf0e582993bdfcd48f92544da174788c05 (patch)
treec2a5bdca37e471c2efd2409a729373589a48eb4f /railties
parented1f67447d571d023e163ce21e9c8322de4fd91c (diff)
downloadrails-d39290cf0e582993bdfcd48f92544da174788c05.tar.gz
rails-d39290cf0e582993bdfcd48f92544da174788c05.tar.bz2
rails-d39290cf0e582993bdfcd48f92544da174788c05.zip
Remove API links and add TODOs #26
Diffstat (limited to 'railties')
-rw-r--r--railties/guides/source/activerecord_validations_callbacks.textile38
1 files changed, 22 insertions, 16 deletions
diff --git a/railties/guides/source/activerecord_validations_callbacks.textile b/railties/guides/source/activerecord_validations_callbacks.textile
index 75c4cf69d5..c4effb374e 100644
--- a/railties/guides/source/activerecord_validations_callbacks.textile
+++ b/railties/guides/source/activerecord_validations_callbacks.textile
@@ -55,34 +55,40 @@ CAUTION: There are many ways to change the state of an object in the database. S
The following methods trigger validations and generally save the object to the database:
-* "create":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002214 (creates an object, but does not save to the database)
-* "create!":http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M002116
-* "save":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002274
-* "save!":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002275
-* "update":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002215
-* "update_attributes":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002281
-* "update_attributes!":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002282
+* +create+
+* +create!+
+* +save+
+* +save!+
+* +update+
+* +update_attributes+
+* +update_attributes!+
The following methods _do not_ trigger validations, but _do_ change the state of the object in the database. They should be used with caution:
-* "decrement!":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002286
-* "decrement_counter":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002224
-* "increment!":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002284
-* "increment_counter":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002223
-* "toggle":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002287
-* "toggle!":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002288
-* "update_all":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002218
-* "update_attribute":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002280
-* "update_counters":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002222
+* +decrement!+
+* +decrement_counter+
+* +increment!+
+* +increment_counter+
+* +toggle+
+* +toggle!+
+* +update_all+
+* +update_attribute+
+* +update_counters+
Note that +save+ has the ability to bypass validations. This technique should be used with caution:
* "save(false)":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002274
+h4. Skipping Validations
+
+TODO: Probably move the list above and mention save(false). Also mention that save(false) doesn't only skip the validations, but a lots of other callbacks too.
+
h4. Object#valid?
To verify whether an object is valid, Active Record uses the +valid?+ method, which basically looks inside the object to see if it has any validation errors. These errors live in a collection that can be accessed through the +errors+ instance method. The process is really simple: If the +errors+ method returns an empty collection, the object is valid and can be saved. Each time a validation fails, an error message is added to the +errors+ collection.
+h4. Object#invalid?
+
h3. Declarative Validation Helpers
Active Record offers many pre-defined validation helpers that you can use directly inside your class definitions. These helpers create validation rules that are commonly used. Every time a validation fails, an error message is added to the object's +errors+ collection, and this message is associated with the field being validated.