From 23de31aae1b0ee6c7bb3c54c0da27ff427020c00 Mon Sep 17 00:00:00 2001 From: CassioMarques Date: Mon, 10 Nov 2008 00:58:04 -0200 Subject: Added documentation for validates_length_of --- .../html/activerecord_validations_callbacks.html | 46 ++++++++++++++++++++++ .../source/activerecord_validations_callbacks.txt | 28 +++++++++++++ 2 files changed, 74 insertions(+) (limited to 'railties/doc') diff --git a/railties/doc/guides/html/activerecord_validations_callbacks.html b/railties/doc/guides/html/activerecord_validations_callbacks.html index 26653d396e..c82f428985 100644 --- a/railties/doc/guides/html/activerecord_validations_callbacks.html +++ b/railties/doc/guides/html/activerecord_validations_callbacks.html @@ -481,6 +481,52 @@ http://www.gnu.org/software/src-highlite -->

The validates_inclusion_of helper has an option :in that receives the set of values that will be accepted. The :in option has an alias called :within that you can use for the same purpose, if you'd like to. In the previous example we used the :message option to show how we can personalize it with the current attribute's value, through the %s format mask.

The default error message for validates_inclusion_of is "is not included in the list".

3.8. The validates_length_of helper

+

This helper validates the length of your attribute's value. It can receive a variety of different options, so you can specify length contraints in different ways.

+
+
+
class Person < ActiveRecord::Base
+  validates_length_of :name, :minimum => 2
+  validates_length_of :bio, :maximum => 500
+  validates_length_of :password, :in => 6..20
+  validates_length_of :registration_number, :is => 6
+end
+
+

The possible length constraint options are:

+
+

The default error messages depend on the type of length validation being performed. You can personalize these messages, using the :wrong_length, :too_long and :too_short options and the %d format mask as a placeholder for the number corresponding to the length contraint being used. You can still use the :message option to specify an error message.

+
+
+
class Person < ActiveRecord::Base
+  validates_length_of :bio, :too_long => "you're writing too much. %d characters is the maximum allowed."
+end
+

3.9. The validates_numericallity_of helper

3.10. The validates_presence_of helper

3.11. The validates_size_of helper

diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt index 4b4b9b4b17..af82f62b6b 100644 --- a/railties/doc/guides/source/activerecord_validations_callbacks.txt +++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -191,6 +191,34 @@ The default error message for +validates_inclusion_of+ is "_is not included in === The +validates_length_of+ helper +This helper validates the length of your attribute's value. It can receive a variety of different options, so you can specify length contraints in different ways. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_length_of :name, :minimum => 2 + validates_length_of :bio, :maximum => 500 + validates_length_of :password, :in => 6..20 + validates_length_of :registration_number, :is => 6 +end +------------------------------------------------------------------ + +The possible length constraint options are: + +* +:minimum+ - The attribute cannot have less than the specified length. +* +:maximum+ - The attribute cannot have more than the specified length. +* +:in+ (or +:within+) - The attribute length must be included in a given interval. The value for this option must be a Ruby range. +* +:is+ - The attribute length must be equal to a given value. + +The default error messages depend on the type of length validation being performed. You can personalize these messages, using the +:wrong_length+, +:too_long+ and +:too_short+ options and the +%d+ format mask as a placeholder for the number corresponding to the length contraint being used. You can still use the +:message+ option to specify an error message. + +[source, ruby] +------------------------------------------------------------------ +class Person < ActiveRecord::Base + validates_length_of :bio, :too_long => "you're writing too much. %d characters is the maximum allowed." +end +------------------------------------------------------------------ + === The +validates_numericallity_of+ helper === The +validates_presence_of+ helper -- cgit v1.2.3