You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NOTE: For `belongs_to` the association presence is validated by default. If you don’t want to have association presence validated, use `optional: true`.
438
+
NOTE: For `belongs_to` the association presence is validated by default. If you
439
+
don’t want to have association presence validated, use `optional: true`.
439
440
440
441
Rails will usually infer the inverse association automatically. In cases where
441
442
you use a custom `:foreign_key` or a `:through` association, it's important to
@@ -480,8 +481,8 @@ end
480
481
```
481
482
482
483
This check is performed only if `terms_of_service` is not `nil`. The default
483
-
error message for this validation is _"must be accepted"_. You can also pass in a
484
-
custom message via the `message` option.
484
+
error message for this validation is _"must be accepted"_. You can also pass in
485
+
a custom message via the `message` option.
485
486
486
487
```ruby
487
488
classPerson < ApplicationRecord
@@ -502,8 +503,8 @@ end
502
503
503
504
This validation is very specific to web applications and this 'acceptance' does
504
505
not need to be recorded anywhere in your database. If you don't have a field for
505
-
it, the validator will create a virtual attribute. If the field does exist in your
506
-
database, the `accept` option must be set to or include `true` or else the
506
+
it, the validator will create a virtual attribute. If the field does exist in
507
+
your database, the `accept` option must be set to or include `true` or else the
507
508
validation will not run.
508
509
509
510
### `confirmation`
@@ -573,8 +574,8 @@ class Promotion < ApplicationRecord
573
574
end
574
575
```
575
576
576
-
The default error message for this validator is _"failed comparison"_. You can also
577
-
pass in a custom message via the `message` option.
577
+
The default error message for this validator is _"failed comparison"_. You can
578
+
also pass in a custom message via the `message` option.
578
579
579
580
These options are all supported:
580
581
@@ -656,8 +657,8 @@ class Account < ApplicationRecord
656
657
end
657
658
```
658
659
659
-
Both validators allow the use of dynamic validation through methods that return an
660
-
enumerable. Here’s an example using a proc for `inclusion`:
660
+
Both validators allow the use of dynamic validation through methods that return
661
+
an enumerable. Here’s an example using a proc for `inclusion`:
661
662
662
663
```ruby
663
664
classCoffee < ApplicationRecord
@@ -727,8 +728,9 @@ together.
727
728
728
729
### `numericality`
729
730
730
-
This validator validates that your attributes have only numeric values. By default,
731
-
it will match an optional sign followed by an integer or floating point number.
731
+
This validator validates that your attributes have only numeric values. By
732
+
default, it will match an optional sign followed by an integer or floating point
733
+
number.
732
734
733
735
To specify that only integer numbers are allowed, set `:only_integer` to true.
734
736
Then it will use the following regular expression to validate the attribute's
@@ -779,8 +781,8 @@ values:
779
781
780
782
### `presence`
781
783
782
-
This validator validates that the specified attributes are not empty. It uses the
783
-
[`Object#blank?`][] method to check if the value is either `nil` or a blank
784
+
This validator validates that the specified attributes are not empty. It uses
785
+
the [`Object#blank?`][] method to check if the value is either `nil` or a blank
784
786
string - that is, a string that is either empty or consists of whitespace.
785
787
786
788
```ruby
@@ -934,9 +936,9 @@ See [`validates_uniqueness_of`][] for more information.
934
936
935
937
### `validates_associated`
936
938
937
-
You should use this validator when your model has associations that always need to
938
-
be validated. Every time you try to save your object, `valid?` will be called on
939
-
each one of the associated objects.
939
+
You should use this validator when your model has associations that always need
940
+
to be validated. Every time you try to save your object, `valid?` will be called
941
+
on each one of the associated objects.
940
942
941
943
```ruby
942
944
classLibrary < ApplicationRecord
@@ -963,9 +965,9 @@ everything up until now can also be used on any object which includes
963
965
964
966
### `validates_each`
965
967
966
-
This validator validates attributes against a block. It doesn't have a predefined
967
-
validation function. You should create one using a block, and every attribute
968
-
passed to [`validates_each`][] will be tested against it.
968
+
This validator validates attributes against a block. It doesn't have a
969
+
predefined validation function. You should create one using a block, and every
970
+
attribute passed to [`validates_each`][] will be tested against it.
969
971
970
972
In the following example, we will reject names and surnames that begin with
971
973
lowercase.
@@ -1036,8 +1038,8 @@ end
1036
1038
We will cover [validation errors](#working-with-validation-errors) in greater
1037
1039
detail later.
1038
1040
1039
-
The [`validates_with`][] validator takes a class, or a list of classes to use for
1040
-
validation.
1041
+
The [`validates_with`][] validator takes a class, or a list of classes to use
0 commit comments