diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md index 2825b4fe36..31ee604514 100644 --- a/guides/source/active_record_validations.md +++ b/guides/source/active_record_validations.md @@ -558,8 +558,8 @@ Since `false.blank?` is true, if you want to validate the presence of a boolean field you should use one of the following validations: ```ruby -validates :boolean_field_name, inclusion: { in: [true, false] } -validates :boolean_field_name, exclusion: { in: [nil] } +validates :boolean_field_name, inclusion: [true, false] +validates :boolean_field_name, exclusion: [nil] ``` By using one of these validations, you will ensure the value will NOT be `nil` @@ -684,7 +684,7 @@ validator class as `options`: ```ruby class GoodnessValidator < ActiveModel::Validator def validate(record) - if options[:fields].any?{|field| record.send(field) == "Evil" } + if options[:fields].any? { |field| record.send(field) == "Evil" } record.errors.add :base, "This person is evil" end end @@ -799,9 +799,9 @@ class Person < ApplicationRecord # Hard-coded message validates :name, presence: { message: "must be given please" } - # Message with dynamic attribute value. %{value} will be replaced with - # the actual value of the attribute. %{attribute} and %{model} also - # available. + # Message with dynamic attribute value. %{value} will be replaced + # with the actual value of the attribute. %{attribute} and %{model} + # are also available. validates :age, numericality: { message: "%{value} seems wrong" } # Proc @@ -810,7 +810,7 @@ class Person < ApplicationRecord # object = person object being validated # data = { model: "Person", attribute: "Username", value: } message: ->(object, data) do - "Hey #{object.name}!, #{data[:value]} is taken already! Try again #{Time.zone.tomorrow}" + "Hey #{object.name}, #{data[:value]} is already taken." end } end @@ -1260,9 +1260,9 @@ Assuming we have a model that's been saved in an instance variable named

<%= pluralize(@article.errors.count, "error") %> prohibited this article from being saved:

<% end %> @@ -1274,7 +1274,7 @@ the entry. ```html
- +
```