LoginSignup
3
4

More than 5 years have passed since last update.

Railsのvalidatesで独自のバリデーションを使用する

Posted at

validatesで独自のバリデーションを使用する

標準validateに無いバリデーションを行いたい場合

models/user.rb
class User < ActiveRecord::Base
  validate :name_valid?

  private

  def name_valid?
    if バリデーション条件
      errors.add(:name)
    end
  end
end
3
4
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
3
4