Commit Graph

152 Commits

Author SHA1 Message Date
zzak
58f8c354c4
Merge pull request #46996 from zzak/ar-callbacks
[Guide] Active Record Callbacks
2023-01-18 10:04:47 +09:00
zzak
0730d6ee26 Run through AR Callbacks guide
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
Co-authored-by: Lachlan Sylvester <lachlan.sylvester@3plearning.com>
2023-01-18 08:12:05 +09:00
Rafael Mendonça França
d994f79c0a
Revert "Merge pull request #46964 from searls/patch-1"
This reverts commit d453eb5ad78125794b0320e134a8a0962f11a446, reversing
changes made to a81be79d4b553fe1bf296e387babaa9b073934b2.

`app/validators` have no special meaning. The code search for
a constant with the suffix `Validator` using `const_get`, so it
can be in any folder that would be autoloaded using that name.
2023-01-16 20:12:46 +00:00
Justin Searls
7881f20d41
Mention that Rails will autoload validators
I don't write custom validators often, but have read this doc many times and it never occurred to me that validators could be autoloaded if placed in `app/validators` until I stumbled on it when trying to figure out how to "register" them (e.g. `EmailValidator` to `email:`). (Separately, it might be worth mentioning explicitly that the kwarg is derived from the class name).
2023-01-11 13:53:56 -05:00
zzak
063299ba20 Run through AR Validations guide 2023-01-08 08:25:12 +09:00
Collin Jilbert
37ac589b32 fix pluralization and punctuation issues 2022-12-01 07:44:14 -06:00
Missy Davies
d49a3abc01 Capitalize headings to match style guidelines
Fix all headings to follow Rails Guides Guidelines
2022-10-17 17:01:28 -10:00
Eddie Lebow
bc5561db23
Formatting typo
on-behalf-of: @Cofense <oss@cofense.com>
2022-09-01 16:09:37 -04:00
Petrik de Heus
81d6012f4f
Merge pull request #45538 from hexdevs/custom-validator-loaded-note
Clarify how `EachValidator` is automatically loaded [ci-skip]
2022-07-10 10:46:36 +02:00
Stefanni Brasil
ecbca0cb1e Make Custom Validators example more clear
The Active Record Validations guide use `Person < ApplicationRecord`
in all examples. When reading about Custom Validators, one of the
examples had a different configuration. By using the same example
everywhere, this change helps the user save time and feel more confident
using the feature.
2022-07-09 17:56:51 -07:00
Alexandre Barret
0dd813c6da Add documentation to customize full_messages on ActiveModel and ActiveRecord
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2022-07-07 13:28:56 -05:00
Masataka Pocke Kuwabara
c280c5d4d9 [guide] Enable syntax highlight for a code in AR validation guide 2022-04-18 23:28:03 +09:00
Petrik
1d08fce0ef Group validates_associated documentation with validates_* [ci-skip]
`validates_associated` makes sure that passed associations are validated
everytime the record is saved. This is unlike other validations that
validate an attribute/association has a certain value.
Typically you won't call:

    validates :books, associated: true

By grouping `validates_associated` with `validates_with` and
`validates_each` it's made clearer `validates_associated` is a bit
different.

With this change the validations are sorted alphabetically.
2022-03-28 20:29:00 +02:00
vamsipavanmahesh
2c37a6553e Fix example related to comparison in Active Record Validations guide
Flipped the example, to show that end_date should be greater than start_date
2022-01-09 12:28:00 +05:30
Ryan Ong
d7d04e6a83
Use Ruby regex for email validation in guide example
existing email regex allowed for invalid emails and invalidated valid emails

- The following emails are shown to be valid emails when they are not:
    - `email_<script></script>_123@example.co.in`
    - `email"123@example.com`
    - `email..123@example.com`
    - `.email123@example.com`
... and a few more

- The following email is shown to be an invalid email when it is valid:
    - `email@123.123.12.123`

Lets use the default ruby regex instead
2021-12-10 10:47:22 -05:00
soartec-lab
613b9ae855 Fixed guide to case_sensitive option for Activerecord uniqueness validator [skip ci] 2021-09-23 00:20:39 +09:00
Jesse van der Pluijm
4862c2faf6 Fix typo: integer numbers (not integral) 2021-09-18 10:21:42 +02:00
Jonathan Hefner
79bb7d0a2b Remove nodoc from EachValidator [ci-skip]
The Active Record Validations guide recommends using `EachValidator`,
and has done so for many years.
2021-07-22 10:35:48 -05:00
Kevin Wiliarty
7fc3826ae0
typo: subject-verb disagreement 2021-05-24 15:02:03 -04:00
Rachael Wright-Munn
9a08a2f09c Add ComparisonValidator to Rails to support validations between two comparable values.
We allow for compare validations in NumericalityValidator, but these
only work on numbers. There are various comparisons people may want
to validate, from dates to strings, to custom comparisons.

```
validates_comparison_of :end_date, greater_than: :start_date
```

Refactor NumericalityValidator to share module Comparison with ComparabilityValidator
* Move creating the option_value into a reusable module
* Separate COMPARE_CHECKS which support compare functions and accept values
* Move odd/even checks to NUMBER_CHECKS as they can only be run on numbers
2021-01-23 21:24:25 -05:00
Michal Papis
2486e887de
Add validate numericality in range 2021-01-05 22:56:58 +01:00
Jonathan Hefner
cb0da4f817 Fix typos, grammar, and formatting [ci-skip]
This is a collection of minor superficial improvements.  It does not
include any significant content changes.
2020-12-28 12:05:53 -06:00
Jonathan Hefner
f3f36e7ef7 Fix syntax highlighting [ci-skip]
This fixes the syntax highlighting of several code snippets by changing
the code fences to the correct language.
2020-12-25 21:03:11 -06:00
Jonathan Hefner
702aaf7e8b Link to API docs in AR Validations guide [ci-skip]
This links the first mention of each method to its API documentation,
similar to a Wikipedia article.  Some subsequent mentions are also
linked, when it suits the surrounding text.
2020-11-05 21:14:24 -06:00
Jonathan Hefner
3c9d7a268f Use irb code fences where applicable [ci-skip]
Using `irb` code fences and the appropriate prompt syntax results in
better syntax highlighting.
2020-11-01 16:29:18 -06:00
Samuel Cochran
c2e51b8394
Change belongs_to example to has_one [ci skip]
This is misleading because belongs_to now already validates presence by
default.
2020-08-31 13:21:52 -04:00
Manuel Meurer
02a93f6afd
improve active record validation docs 2020-08-03 12:18:47 +02:00
Jonathan Hefner
3a90f12317 Use appropriate code fences [ci skip]
Follow-up to #39620.

This commit changes a few overlooked code fences to `bash`, and changes
a few IRB session snippets to be only Ruby code with a `ruby` fence.
2020-07-08 14:51:57 -05:00
Eugene Kenny
e6f8bfe1dc Note that insert_all and friends skip callbacks and validations [ci skip] 2020-07-08 12:17:43 +01:00
Juarez Lustosa
44d44777ce [ci skip] Increase info on validate presence for association 2020-06-20 22:02:24 -03:00
Santiago Bartesaghi
0cb67a6307 Documentation: Add touch_all to callbacks and validations guides [ci skip] 2020-06-20 03:30:25 -03:00
Ryuta Kamizono
6a4395f466 Deprecate starts_with? and ends_with? for String core extensions
In the past, we sometimes hit missing `Symbol#start_with?` and
`Symbol#end_with?`.

63256bc5d7
a8e812964d

So I proposed `Symbol#start_with?` and `Symbol#end_with?` to allow duck
typing that methods for String and Symbol, then now it is available in
Ruby 2.7.

https://bugs.ruby-lang.org/issues/16348

Using `String#starts_with?` and `String#ends_with?` could not be gained
that conveniency, so it is preferable to not use these in the future.
2020-05-05 15:51:24 +09:00
cjilbert504
1583d8ee42
active_record_validations.md grammer fix [ci skip]
An extremely small readability change to line 269 [ci skip].
2020-04-15 11:15:50 -05:00
Rafael França
6f6f4e40ab
Merge pull request #36125 from lulalala/doc-for-model-errors
Document update for ActiveModel#errors
2020-04-13 14:11:55 -04:00
Evan Brodie
5b4025b76b Adds default message for :only_integer validation
This adds consistency to the documentation because all other options to the `:numericality` validator have their default error messages mentioned.
2020-03-24 21:39:02 -04:00
lulalala
fcd1e41e82 Document on ActiveModel::Errors changes
Mark private constants

Display alternative for deprecation removal warning

Annotate Error's attributes

More emphasis on adding an error instead of message

Rewrite scaffold template using new errors API

Set first and last with behavior change deprecation

Update more doc and example

Add inspect for easier debugging
2020-01-14 23:55:09 +08:00
Gannon McGibbon
b5c9974fa7 Add ActiveRecord::Validations::NumericalityValidator
Add Active Record numericality validator with support for casting
floats using a database columns' precision value.
2020-01-06 19:01:29 -05:00
Haroon Ahmed
db1ae8cbb4 remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
Petrik
2e84228d0e Add missing languages for guides code blocks [ci skip]
Some code examples were missing the language used for code highlighting.
2019-12-17 19:38:45 -05:00
Kevin Jacoby
b0743dda8c Clarify documentation by removing charged words
Using words such as 'just', 'simply' and 'easy' implies to the reader
that the tasks they are trying to accomplish are tasks that anyone can
do, which might then frustrate them if they find it difficult to
complete.

This commit rephrases some usage of these words to aid understanding in
the readers without making them feel belittled.

[ci skip]
2019-12-12 19:43:51 +00:00
Nursoltan Saipolda
3ffc3635b9 fix some grammar errors on guide doc. 2019-10-24 15:38:12 +08:00
Louis-Michel Couture
467e79bb8b
Update MySQL links to the current version of the manual [ci skip]
Accessing the MySQL manual without a specific version number will redirect to the latest version of the manual.
Remove non functional id from a comment in favor an explicit message
2019-10-03 20:22:29 -04:00
lulalala
abee034368 Raise deprecation for calling [:f] = 'b' or [:f] << 'b'
Revert some tests to ensure back compatibility
2019-03-31 22:59:12 +08:00
Nathaniel Suchy
d9f1cc05b5 Update links and code examples in the guides to use HTTPS where the host supports it. 2019-03-06 15:21:07 -05:00
Shodai Suzuki
02e6abd8fd Delete documentation inconsistency 'finally' for AR callbacks [ci skip] (#35303) 2019-02-19 13:31:25 +09:00
Gannon McGibbon
27b3b4666c
Merge pull request #34415 from Ana06/present_associations
Clarify the validation of present associations
2018-11-09 14:53:56 -05:00
Ana María Martínez Gómez
e53d2325d5 Clarify the validation of present associations
I think that it is not clear what means that _an association is
present_. Add that it is checking that the foreign key is not empty and
that the referenced object exists to clarify it.
2018-11-09 15:15:09 +01:00
Ryuta Kamizono
7d89337b17
Merge pull request #33348 from ruralocity/update-validation-contexts-guide
Update guide for validation custom contexts [ci skip]
2018-09-28 18:42:09 +09:00
Ana María Martínez Gómez
3cb491f327 Add lambdas in conditional validations
As `Lambdas` are a type of `Proc`, they can also be used in the
`if`/`unless` option of a validation to decide when the validation is
executed. Add this case to the guide for clarification.

Closes https://github.com/rails/rails/issues/33212
2018-08-07 17:35:13 +02:00
Matthew Draper
ec387c6dd9
Merge pull request #33229 from albertoalmagro/albertoalmagro/prefer-rails-command-over-bin-rails
Prefer rails command over bin/rails
2018-07-25 04:10:29 +09:30