aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc
diff options
context:
space:
mode:
authorCassioMarques <cassiommc@gmail.com>2008-11-10 20:24:51 -0200
committerCassioMarques <cassiommc@gmail.com>2008-11-10 20:24:51 -0200
commit0668ab67bf6b32950113995303446840ae57d5d9 (patch)
treed187c76abc47f08b23f7e793d9940644d16ecbae /railties/doc
parent5affa79f2a5fe73e4bf9ddf1bd2abdfa5667361b (diff)
downloadrails-0668ab67bf6b32950113995303446840ae57d5d9.tar.gz
rails-0668ab67bf6b32950113995303446840ae57d5d9.tar.bz2
rails-0668ab67bf6b32950113995303446840ae57d5d9.zip
Added documentation for validates_presence_of
Diffstat (limited to 'railties/doc')
-rw-r--r--railties/doc/guides/html/activerecord_validations_callbacks.html29
-rw-r--r--railties/doc/guides/source/activerecord_validations_callbacks.txt21
2 files changed, 50 insertions, 0 deletions
diff --git a/railties/doc/guides/html/activerecord_validations_callbacks.html b/railties/doc/guides/html/activerecord_validations_callbacks.html
index 6feaae68ea..2e5044eb6e 100644
--- a/railties/doc/guides/html/activerecord_validations_callbacks.html
+++ b/railties/doc/guides/html/activerecord_validations_callbacks.html
@@ -539,6 +539,35 @@ http://www.gnu.org/software/src-highlite -->
</tt></pre></div></div>
<div class="para"><p>The default error message for <tt>validates_numericallity_of</tt> is "<em>is not a number</em>".</p></div>
<h3 id="_the_tt_validates_presence_of_tt_helper">3.10. The <tt>validates_presence_of</tt> helper</h3>
+<div class="para"><p>This helper validates that the attributes are not empty. It uses the <tt>blank?</tt> method to check if the value is either <tt>nil</tt> or an empty string (if the string has only spaces, it will still be considered empty).</p></div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> Person <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base
+ validates_presence_of <span style="color: #990000">:</span>name<span style="color: #990000">,</span> <span style="color: #990000">:</span>login<span style="color: #990000">,</span> <span style="color: #990000">:</span>email
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+</tt></pre></div></div>
+<div class="admonitionblock">
+<table><tr>
+<td class="icon">
+<img src="./images/icons/note.png" alt="Note" />
+</td>
+<td class="content">If you want to be sure that an association is present, you'll need to test if the foreign key used to map the association is present, and not the associated object itself.</td>
+</tr></table>
+</div>
+<div class="listingblock">
+<div class="content"><!-- Generator: GNU source-highlight 2.9
+by Lorenzo Bettini
+http://www.lorenzobettini.it
+http://www.gnu.org/software/src-highlite -->
+<pre><tt><span style="font-weight: bold"><span style="color: #0000FF">class</span></span> LineItem <span style="color: #990000">&lt;</span> ActiveRecord<span style="color: #990000">::</span>Base
+ belongs_to <span style="color: #990000">:</span>order
+ validates_presence_of <span style="color: #990000">:</span>order_id
+<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
+</tt></pre></div></div>
+<div class="para"><p>The default error message for <tt>validates_presence_of</tt> is "<em>can't be empty</em>".</p></div>
<h3 id="_the_tt_validates_size_of_tt_helper">3.11. The <tt>validates_size_of</tt> helper</h3>
<h3 id="_the_validates_uniqueness_of_helper">3.12. The validates_uniqueness_of+ helper</h3>
</div>
diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt
index b26ebfed41..568ab8bc23 100644
--- a/railties/doc/guides/source/activerecord_validations_callbacks.txt
+++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt
@@ -237,6 +237,27 @@ The default error message for +validates_numericallity_of+ is "_is not a number_
=== The +validates_presence_of+ helper
+This helper validates that the attributes are not empty. It uses the +blank?+ method to check if the value is either +nil+ or an empty string (if the string has only spaces, it will still be considered empty).
+
+[source, ruby]
+------------------------------------------------------------------
+class Person < ActiveRecord::Base
+ validates_presence_of :name, :login, :email
+end
+------------------------------------------------------------------
+
+NOTE: If you want to be sure that an association is present, you'll need to test if the foreign key used to map the association is present, and not the associated object itself.
+
+[source, ruby]
+------------------------------------------------------------------
+class LineItem < ActiveRecord::Base
+ belongs_to :order
+ validates_presence_of :order_id
+end
+------------------------------------------------------------------
+
+The default error message for +validates_presence_of+ is "_can't be empty_".
+
=== The +validates_size_of+ helper
=== The validates_uniqueness_of+ helper