diff options
author | CassioMarques <cassiommc@gmail.com> | 2009-01-14 22:22:56 -0200 |
---|---|---|
committer | CassioMarques <cassiommc@gmail.com> | 2009-01-14 23:51:07 -0200 |
commit | 9cc7a1e04dc99dc47d11b6303fdb011532ce19b1 (patch) | |
tree | 8c12d73341db12df68cb8082e9d9a77988451c9e | |
parent | baa0ce8745611ba271b70dd4e29b4eb913387e22 (diff) | |
download | rails-9cc7a1e04dc99dc47d11b6303fdb011532ce19b1.tar.gz rails-9cc7a1e04dc99dc47d11b6303fdb011532ce19b1.tar.bz2 rails-9cc7a1e04dc99dc47d11b6303fdb011532ce19b1.zip |
Adding options for validates_numericality_of, adding author name with link at the end of the page
-rw-r--r-- | railties/doc/guides/html/activerecord_validations_callbacks.html | 43 | ||||
-rw-r--r-- | railties/doc/guides/source/activerecord_validations_callbacks.txt | 15 |
2 files changed, 55 insertions, 3 deletions
diff --git a/railties/doc/guides/html/activerecord_validations_callbacks.html b/railties/doc/guides/html/activerecord_validations_callbacks.html index e1ede87403..61ccbbc1ca 100644 --- a/railties/doc/guides/html/activerecord_validations_callbacks.html +++ b/railties/doc/guides/html/activerecord_validations_callbacks.html @@ -612,6 +612,44 @@ http://www.gnu.org/software/src-highlite --> validates_numericality_of <span style="color: #990000">:</span>points
validates_numericality_of <span style="color: #990000">:</span>games_played<span style="color: #990000">,</span> <span style="color: #990000">:</span>integer_only <span style="color: #990000">=></span> <span style="font-weight: bold"><span style="color: #0000FF">true</span></span>
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
+<div class="paragraph"><p>Besides <tt>:only_integer</tt>, the <tt>validates_numericality_of</tt> helper also accepts the following options to add constraints to acceptable values:</p></div>
+<div class="ulist"><ul>
+<li>
+<p>
+<tt>:greater_than</tt> - Specifies the value must be greater than the supplied value. The default error message for this option is "<em>must be greater than (value)</em>"
+</p>
+</li>
+<li>
+<p>
+<tt>:greater_than_or_equal_to</tt> - Specifies the value must be greater than or equal the supplied value. The default error message for this option is "<em>must be greater than or equal to (value)</em>"
+</p>
+</li>
+<li>
+<p>
+<tt>:equal_to</tt> - Specifies the value must be equal to the supplied value. The default error message for this option is "<em>must be equal to (value)</em>"
+</p>
+</li>
+<li>
+<p>
+<tt>:less_than</tt> - Specifies the value must be less than the supplied value. The default error message for this option is "<em>must e less than (value)</em>"
+</p>
+</li>
+<li>
+<p>
+<tt>:less_than_or_equal_to</tt> - Specifies the value must be less than or equal the supplied value. The default error message for this option is "<em>must be less or equal to (value)</em>"
+</p>
+</li>
+<li>
+<p>
+<tt>:odd</tt> - Specifies the value must be an odd number if set to true. The default error message for this option is "<em>must be odd</em>"
+</p>
+</li>
+<li>
+<p>
+<tt>:even</tt> - Specifies the value must be an even number if set to true. The default error message for this option is "<em>must be even</em>"
+</p>
+</li>
+</ul></div>
<div class="paragraph"><p>The default error message for <tt>validates_numericality_of</tt> is "<em>is not a number</em>".</p></div>
<h3 id="_the_tt_validates_presence_of_tt_helper">2.9. The <tt>validates_presence_of</tt> helper</h3>
<div class="paragraph"><p>This helper validates that the specified 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>
@@ -645,7 +683,7 @@ http://www.gnu.org/software/src-highlite --> <td class="icon">
<img src="./images/icons/note.png" alt="Note" />
</td>
-<td class="content">If you want to validate the presence of a boolean field (where the real values are true and false), you should use validates_inclusion_of :field_name, :in => [true, false] This is due to the way Object#blank? handles boolean values. false.blank? # => true</td>
+<td class="content">If you want to validate the presence of a boolean field (where the real values are true and false), you should use validates_inclusion_of :field_name, :in ⇒ [true, false] This is due to the way Object#blank? handles boolean values. false.blank? # ⇒ true</td>
</tr></table>
</div>
<div class="paragraph"><p>The default error message for <tt>validates_presence_of</tt> is "<em>can’t be empty</em>".</p></div>
@@ -1351,7 +1389,8 @@ config<span style="color: #990000">.</span>active_record<span style="color: #990 </div>
<h2 id="_changelog">14. Changelog</h2>
<div class="sectionbody">
-<div class="paragraph"><p><a href="http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks">http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks</a></p></div>
+<div class="paragraph"><p><a href="http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks">Lighthouse ticket</a></p></div>
+<div class="paragraph"><p>January 9, 2009: Initial version by <a href="http://guides.rails.info/authors.html#cmarques">Cássio Marques</a></p></div>
</div>
</div> diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt index 8393d183e9..849954a190 100644 --- a/railties/doc/guides/source/activerecord_validations_callbacks.txt +++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -227,6 +227,17 @@ class Player < ActiveRecord::Base end ------------------------------------------------------------------ +Besides +:only_integer+, the +validates_numericality_of+ helper also accepts the following options to add constraints to acceptable values: + +* +:greater_than+ - Specifies the value must be greater than the supplied value. The default error message for this option is "_must be greater than (value)_" +* +:greater_than_or_equal_to+ - Specifies the value must be greater than or equal the supplied value. The default error message for this option is "_must be greater than or equal to (value)_" +* +:equal_to+ - Specifies the value must be equal to the supplied value. The default error message for this option is "_must be equal to (value)_" +* +:less_than+ - Specifies the value must be less than the supplied value. The default error message for this option is "_must e less than (value)_" +* +:less_than_or_equal_to+ - Specifies the value must be less than or equal the supplied value. The default error message for this option is "_must be less or equal to (value)_" +* +:odd+ - Specifies the value must be an odd number if set to true. The default error message for this option is "_must be odd_" +* +:even+ - Specifies the value must be an even number if set to true. The default error message for this option is "_must be even_" + + The default error message for +validates_numericality_of+ is "_is not a number_". === The +validates_presence_of+ helper @@ -847,4 +858,6 @@ By convention, you should always save your observers' source files inside *app/m == Changelog -http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks +http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks[Lighthouse ticket] + +January 9, 2009: Initial version by http://guides.rails.info/authors.html#cmarques[Cássio Marques] |