From 9cc7a1e04dc99dc47d11b6303fdb011532ce19b1 Mon Sep 17 00:00:00 2001 From: CassioMarques Date: Wed, 14 Jan 2009 22:22:56 -0200 Subject: Adding options for validates_numericality_of, adding author name with link at the end of the page --- .../html/activerecord_validations_callbacks.html | 43 +++++++++++++++++++++- .../source/activerecord_validations_callbacks.txt | 15 +++++++- 2 files changed, 55 insertions(+), 3 deletions(-) (limited to 'railties/doc/guides') 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 :points validates_numericality_of :games_played, :integer_only => true end +

Besides :only_integer, the validates_numericality_of helper also accepts the following options to add constraints to acceptable values:

+

The default error message for validates_numericality_of is "is not a number".

2.9. The validates_presence_of helper

This helper validates that the specified 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).

@@ -645,7 +683,7 @@ http://www.gnu.org/software/src-highlite --> Note -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 +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

The default error message for validates_presence_of is "can’t be empty".

@@ -1351,7 +1389,8 @@ config.active_record14. Changelog 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] -- cgit v1.2.3