From 10c7c053a1cfee6f5c87a718bb6913adebaba9ba Mon Sep 17 00:00:00 2001 From: CassioMarques Date: Mon, 10 Nov 2008 00:03:16 -0200 Subject: Added documentation for validates_inclusion_of --- .../html/activerecord_validations_callbacks.html | 25 +++++++++++++++++++++- .../source/activerecord_validations_callbacks.txt | 13 +++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) (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 efef58adea..26653d396e 100644 --- a/railties/doc/guides/html/activerecord_validations_callbacks.html +++ b/railties/doc/guides/html/activerecord_validations_callbacks.html @@ -454,9 +454,32 @@ http://www.gnu.org/software/src-highlite --> end

The validates_exclusion_of helper has an option :in that receives the set of values that will not be accepted for the validated attributes. 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_exclusion_of is "is not included in the list"

+

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

3.6. The validates_format_of helper

+

This helper validates the attributes's values by testing if they match a given pattern. This pattern must be specified using a Ruby regular expression, which must be passed through the :with option.

+
+
+
class Product < ActiveRecord::Base
+  validates_format_of :description, :with => /^[a-zA-Z]+$/, :message => "Only letters allowed"
+end
+
+

The default error message for validates_format_of is "is invalid".

3.7. The validates_inclusion_of helper

+

This helper validates that the attributes' values are included in a given set. In fact, this set can be any enumerable object.

+
+
+
class Coffee < ActiveRecord::Base
+  validates_inclusion_of :size, :in => %w(small medium large), :message => "%s is not a valid size"
+end
+
+

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

3.9. The validates_numericallity_of helper

3.10. The validates_presence_of helper

diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt index f61bea9d3d..4b4b9b4b17 100644 --- a/railties/doc/guides/source/activerecord_validations_callbacks.txt +++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -176,6 +176,19 @@ The default error message for +validates_format_of+ is "_is invalid_". === The +validates_inclusion_of+ helper +This helper validates that the attributes' values are included in a given set. In fact, this set can be any enumerable object. + +[source, ruby] +------------------------------------------------------------------ +class Coffee < ActiveRecord::Base + validates_inclusion_of :size, :in => %w(small medium large), :message => "%s is not a valid size" +end +------------------------------------------------------------------ + +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_". + === The +validates_length_of+ helper === The +validates_numericallity_of+ helper -- cgit v1.2.3