LoginSignup
1
0

More than 5 years have passed since last update.

特定の条件(複数)の場合のみvalidateを実行させる

Last updated at Posted at 2018-04-25

単体の場合

# def_valid_a?がtrueの場合validate実行
validates_presence_of :title, if: :def_valid_a?

複数の場合

# def_valid_a? または def_valid_b? がtrueの場合validate実行
validates_presence_of :title, if: -> {def_valid_a? || def_valid_b?}

※validates_presence_of
値が空でないか

1
0
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
1
0