aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/html/activerecord_validations_callbacks.html
diff options
context:
space:
mode:
authorCassioMarques <cassiommc@gmail.com>2008-12-13 21:22:34 -0200
committerCassioMarques <cassiommc@gmail.com>2008-12-13 21:22:34 -0200
commit596cd8317b9917941f90a8643d54335f7406b8b3 (patch)
tree29956319980e86e2e1b2a062fe769d13b81f9a8a /railties/doc/guides/html/activerecord_validations_callbacks.html
parent7bf5fb07ad8ab1c6202614283b59ccf4e8ec37d2 (diff)
downloadrails-596cd8317b9917941f90a8643d54335f7406b8b3.tar.gz
rails-596cd8317b9917941f90a8643d54335f7406b8b3.tar.bz2
rails-596cd8317b9917941f90a8643d54335f7406b8b3.zip
Some more info about the effect of calling the clear method upon a model's errors collection (AR Validations an Callbacks Guide)
Diffstat (limited to 'railties/doc/guides/html/activerecord_validations_callbacks.html')
-rw-r--r--railties/doc/guides/html/activerecord_validations_callbacks.html11
1 files changed, 7 insertions, 4 deletions
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 -->
&gt;&gt; p.new_record?
=&gt; false</tt></pre>
</div></div>
-<div class="para"><p>Saving new records means sending an SQL insert operation to the database, while saving existing records (by calling either <tt>save</tt> or <tt>update_attributes</tt>) 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.</p></div>
+<div class="para"><p>Saving new records means sending an SQL insert operation to the database, while saving existing records (by calling either <tt>save</tt> or <tt>update_attributes</tt>) 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.</p></div>
<div class="admonitionblock">
<table><tr>
<td class="icon">
@@ -899,7 +899,7 @@ person<span style="color: #990000">.</span>errors<span style="color: #990000">.<
<div class="ilist"><ul>
<li>
<p>
-<tt>clear</tt> is used when you intentionally wants to clear all the messages in the <tt>errors</tt> collection.
+<tt>clear</tt> is used when you intentionally want to clear all the messages in the <tt>errors</tt> collection. However, calling <tt>errors.clear</tt> upon an invalid object won't make it valid: the <tt>errors</tt> collection will now be empty, but the next time you call <tt>valid?</tt> or any method that tries to save this object to the database, the validations will run. If any of them fails, the <tt>errors</tt> collection will get filled again.
</p>
</li>
</ul></div>
@@ -914,12 +914,15 @@ http://www.gnu.org/software/src-highlite -->
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
person <span style="color: #990000">=</span> Person<span style="color: #990000">.</span>new
-puts person<span style="color: #990000">.</span>valid? <span style="font-style: italic"><span style="color: #9A1900"># =&gt; false</span></span>
+person<span style="color: #990000">.</span>valid? <span style="font-style: italic"><span style="color: #9A1900"># =&gt; false</span></span>
person<span style="color: #990000">.</span>errors<span style="color: #990000">.</span>on<span style="color: #990000">(:</span>name<span style="color: #990000">)</span>
<span style="font-style: italic"><span style="color: #9A1900"># =&gt; ["can't be blank", "is too short (minimum is 3 characters)"]</span></span>
person<span style="color: #990000">.</span>errors<span style="color: #990000">.</span>clear
-person<span style="color: #990000">.</span>errors <span style="font-style: italic"><span style="color: #9A1900"># =&gt; nil</span></span>
+person<span style="color: #990000">.</span>errors<span style="color: #990000">.</span>empty? <span style="font-style: italic"><span style="color: #9A1900"># =&gt; true</span></span>
+p<span style="color: #990000">.</span>save <span style="font-style: italic"><span style="color: #9A1900"># =&gt; false</span></span>
+p<span style="color: #990000">.</span>errors<span style="color: #990000">.</span>on<span style="color: #990000">(:</span>name<span style="color: #990000">)</span>
+<span style="font-style: italic"><span style="color: #9A1900"># =&gt; ["can't be blank", "is too short (minimum is 3 characters)"]</span></span>
</tt></pre></div></div>
</div>
<h2 id="_callbacks">8. Callbacks</h2>