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 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'railties/doc/guides/html') 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

-- cgit v1.2.3