diff options
author | Jon Moss <maclover7@users.noreply.github.com> | 2017-02-17 20:54:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-17 20:54:21 -0500 |
commit | 74689fda0ce7612d87c620a36097d2d7451f53c0 (patch) | |
tree | 58f2840b07c57e0e3b02d5e3a693443d5ea3fa39 /guides | |
parent | c059caab7bcf40dec4902ac21cef673625da2a24 (diff) | |
parent | 53ff5fc62f9d11b6f60d371df959137f4bf40728 (diff) | |
download | rails-74689fda0ce7612d87c620a36097d2d7451f53c0.tar.gz rails-74689fda0ce7612d87c620a36097d2d7451f53c0.tar.bz2 rails-74689fda0ce7612d87c620a36097d2d7451f53c0.zip |
Merge pull request #28058 from y-yagi/follow_up_to_27608
Remove deprecate passing string to `:if` and `:unless` conditional options [ci skip]
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/active_record_callbacks.md | 12 | ||||
-rw-r--r-- | guides/source/active_record_validations.md | 12 |
2 files changed, 1 insertions, 23 deletions
diff --git a/guides/source/active_record_callbacks.md b/guides/source/active_record_callbacks.md index 666d987f8c..77bd3c97e8 100644 --- a/guides/source/active_record_callbacks.md +++ b/guides/source/active_record_callbacks.md @@ -288,7 +288,7 @@ Article destroyed Conditional Callbacks --------------------- -As with validations, we can also make the calling of a callback method conditional on the satisfaction of a given predicate. We can do this using the `:if` and `:unless` options, which can take a symbol, a string, a `Proc` or an `Array`. You may use the `:if` option when you want to specify under which conditions the callback **should** be called. If you want to specify the conditions under which the callback **should not** be called, then you may use the `:unless` option. +As with validations, we can also make the calling of a callback method conditional on the satisfaction of a given predicate. We can do this using the `:if` and `:unless` options, which can take a symbol, a `Proc` or an `Array`. You may use the `:if` option when you want to specify under which conditions the callback **should** be called. If you want to specify the conditions under which the callback **should not** be called, then you may use the `:unless` option. ### Using `:if` and `:unless` with a `Symbol` @@ -300,16 +300,6 @@ class Order < ApplicationRecord end ``` -### Using `:if` and `:unless` with a String - -You can also use a string that will be evaluated using `eval` and hence needs to contain valid Ruby code. You should use this option only when the string represents a really short condition: - -```ruby -class Order < ApplicationRecord - before_save :normalize_card_number, if: "paid_with_card?" -end -``` - ### Using `:if` and `:unless` with a `Proc` Finally, it is possible to associate `:if` and `:unless` with a `Proc` object. This option is best suited when writing short validation methods, usually one-liners: diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md index 665e97c470..32b38cde5e 100644 --- a/guides/source/active_record_validations.md +++ b/guides/source/active_record_validations.md @@ -916,18 +916,6 @@ class Order < ApplicationRecord end ``` -### Using a String with `:if` and `:unless` - -You can also use a string that will be evaluated using `eval` and needs to -contain valid Ruby code. You should use this option only when the string -represents a really short condition. - -```ruby -class Person < ApplicationRecord - validates :surname, presence: true, if: "name.nil?" -end -``` - ### Using a Proc with `:if` and `:unless` Finally, it's possible to associate `:if` and `:unless` with a `Proc` object |