From e05e9979075b37342b7c88e557dbffd672b2086a Mon Sep 17 00:00:00 2001 From: Jeff Kreeftmeijer Date: Wed, 9 Mar 2011 10:58:18 +0100 Subject: Add a note to discourage users from using presence validators with allow_(nil|blank) --- railties/guides/source/active_record_validations_callbacks.textile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'railties/guides/source/active_record_validations_callbacks.textile') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 58a184a48e..2301d6715d 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -463,9 +463,11 @@ h3. Common Validation Options There are some common options that all the validation helpers can use. Here they are, except for the +:if+ and +:unless+ options, which are discussed later in "Conditional Validation":#conditional-validation. +TIP: Note that +allow_nil+ and +allow_blank+ will be ignored when using the presence validator. Please use the length validator if you want to validate if something is a specific length but allows for +nil+ values. + h4. +:allow_nil+ -The +:allow_nil+ option skips the validation when the value being validated is +nil+. Using +:allow_nil+ with +validates_presence_of+ allows for +nil+, but any other +blank?+ value will still be rejected. +The +:allow_nil+ option skips the validation when the value being validated is +nil+. class Coffee < ActiveRecord::Base -- cgit v1.2.3 From 439ccdc3cf2aa46e22a8dfb7debcee073127df86 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Thu, 10 Mar 2011 19:58:55 +0530 Subject: update plugin urls to reflect official maintainers --- railties/guides/source/active_record_validations_callbacks.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/guides/source/active_record_validations_callbacks.textile') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index 2301d6715d..bfb06a9cd5 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -744,7 +744,7 @@ Rails maintains an official plugin that provides helpers to display the error me h4. Installing as a plugin -$ rails plugin install git://github.com/rails/dynamic_form.git +$ rails plugin install git://github.com/joelmoss/dynamic_form.git h4 Installing as a Gem -- cgit v1.2.3 From de5e41f855a8d715d99eec6195f9b31cc4048b99 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Mon, 14 Mar 2011 21:59:58 +0100 Subject: move the tips about :allow_(nil|blank) near their explanations, also no need to say these are options for all validators if they are not --- .../guides/source/active_record_validations_callbacks.textile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'railties/guides/source/active_record_validations_callbacks.textile') diff --git a/railties/guides/source/active_record_validations_callbacks.textile b/railties/guides/source/active_record_validations_callbacks.textile index bfb06a9cd5..e5349d546c 100644 --- a/railties/guides/source/active_record_validations_callbacks.textile +++ b/railties/guides/source/active_record_validations_callbacks.textile @@ -461,9 +461,7 @@ The block receives the model, the attribute's name and the attribute's value. Yo h3. Common Validation Options -There are some common options that all the validation helpers can use. Here they are, except for the +:if+ and +:unless+ options, which are discussed later in "Conditional Validation":#conditional-validation. - -TIP: Note that +allow_nil+ and +allow_blank+ will be ignored when using the presence validator. Please use the length validator if you want to validate if something is a specific length but allows for +nil+ values. +These are common validation options: h4. +:allow_nil+ @@ -476,6 +474,8 @@ class Coffee < ActiveRecord::Base end +TIP: +:allow_nil+ is ignored by the presence validator. + h4. +:allow_blank+ The +:allow_blank+ option is similar to the +:allow_nil+ option. This option will let validation pass if the attribute's value is +blank?+, like +nil+ or an empty string for example. @@ -489,6 +489,8 @@ Topic.create("title" => "").valid? # => true Topic.create("title" => nil).valid? # => true +TIP: +:allow_blank+ is ignored by the presence validator. + h4. +:message+ As you've already seen, the +:message+ option lets you specify the message that will be added to the +errors+ collection when validation fails. When this option is not used, Active Record will use the respective default error message for each validation helper. -- cgit v1.2.3