0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

validateに条件分岐を設定する

Posted at

validateに条件分岐を設定する

 validateにifやunlessの条件分岐を設定する際の書き方。

validate :判定に使用するメソッド, if: -> { 条件 }
# 具体例
validate :hoge, if: -> { Rails.env.production? }

動作確認

 以下で選択したレコードに対してバリデーションの判定を行う。

バリデーションを設定したクラス.find(動作確認に使用するレコード).valid?
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?