Skip to content

Commit

Permalink
Merge pull request #1724 from yasslab/update80_active_record_validations
Browse files Browse the repository at this point in the history
[8.0] active_record_validations.mdの原文更新を訳文に反映
  • Loading branch information
hachi8833 authored Nov 13, 2024
2 parents cd0d261 + 315b550 commit 0028e42
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions guides/source/ja/active_record_validations.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,16 @@ end

```ruby
class Person < ApplicationRecord
validates :terms_of_service, acceptance: { message: 'must be abided' }
validates :terms_of_service, acceptance: { message: "must be abided" }
end
```

このヘルパーでは`:accept`オプションも渡せます。このオプションは、「同意可能(acceptable)」とみなす値を指定します。デフォルトは`['1', true]`ですが、変更は簡単です。

```ruby
class Person < ApplicationRecord
validates :terms_of_service, acceptance: { accept: 'yes' }
validates :eula, acceptance: { accept: ['TRUE', 'accepted'] }
validates :terms_of_service, acceptance: { accept: "yes" }
validates :eula, acceptance: { accept: ["TRUE", "accepted"] }
end
```

Expand Down Expand Up @@ -627,7 +627,7 @@ NOTE: [`validates_associated`][]はActive Recordオブジェクトでしか利
```ruby
class Person < ApplicationRecord
validates_each :name, :surname do |record, attr, value|
record.errors.add(attr, '大文字で始まる必要があります') if /\A[[:lower:]]/.match?(value)
record.errors.add(attr, "大文字で始まる必要があります") if /\A[[:lower:]]/.match?(value)
end
end
```
Expand Down Expand Up @@ -1004,7 +1004,7 @@ end
```ruby
class MyValidator < ActiveModel::Validator
def validate(record)
unless record.name.start_with? 'X'
unless record.name.start_with? "X"
record.errors.add :name, "名前はXで始まる必要があります"
end
end
Expand Down

0 comments on commit 0028e42

Please sign in to comment.