aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-05-05 16:29:20 -0500
committerRafael França <rafaelmfranca@gmail.com>2016-05-05 16:29:20 -0500
commit1949412a868ccf5addc12b7569f6ebbf4b6488e4 (patch)
tree2f58157b9c08824cec604dfd10348aaee14cdf3d /guides
parent063bc008b3705abc7e762484efb1a3d2081910bc (diff)
parentf7d7147ae6b40ab06750e58c2edcc1c8046f90cb (diff)
downloadrails-1949412a868ccf5addc12b7569f6ebbf4b6488e4.tar.gz
rails-1949412a868ccf5addc12b7569f6ebbf4b6488e4.tar.bz2
rails-1949412a868ccf5addc12b7569f6ebbf4b6488e4.zip
Merge pull request #24799 from prathamesh-sonpatki/18439-followup
Active Model: Improve CHANGELOG and documentation for `validates_acceptance_of` [ci skip]
Diffstat (limited to 'guides')
-rw-r--r--guides/source/active_record_validations.md25
1 files changed, 17 insertions, 8 deletions
diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md
index 1cf4abce10..936d6a30b8 100644
--- a/guides/source/active_record_validations.md
+++ b/guides/source/active_record_validations.md
@@ -278,12 +278,6 @@ form was submitted. This is typically used when the user needs to agree to your
application's terms of service, confirm that some text is read, or any similar
concept.
-This validation is very specific to web applications and this
-'acceptance' does not need to be recorded anywhere in your database. If you
-don't have a field for it, the helper will just create a virtual attribute. If
-the field does exist in your database, the `accept` option must be set to
-`true` or else the validation will not run.
-
```ruby
class Person < ApplicationRecord
validates :terms_of_service, acceptance: true
@@ -292,16 +286,31 @@ end
This check is performed only if `terms_of_service` is not `nil`.
The default error message for this helper is _"must be accepted"_.
+You can also pass custom message via the `message` option.
-It can receive an `:accept` option, which determines the value that will be
-considered acceptance. It defaults to "1" and can be easily changed.
+```ruby
+class Person < ApplicationRecord
+ validates :terms_of_service, acceptance: true, message: 'must be abided'
+end
+```
+
+It can also receive an `:accept` option, which determines the allowed values
+that will be considered as accepted. It defaults to `['1', true]` and can be
+easily changed.
```ruby
class Person < ApplicationRecord
validates :terms_of_service, acceptance: { accept: 'yes' }
+ validates :eula, acceptance: { accept: ['TRUE', 'accepted'] }
end
```
+This validation is very specific to web applications and this
+'acceptance' does not need to be recorded anywhere in your database. If you
+don't have a field for it, the helper will just create a virtual attribute. If
+the field does exist in your database, the `accept` option must be set to
+or include `true` or else the validation will not run.
+
### `validates_associated`
You should use this helper when your model has associations with other models