LoginSignup
0
0

More than 1 year has passed since last update.

deviseに自動的に設けられているバリデーション

Posted at

アウトプット

deviseを用いて、ユーザー情報を管理するモデル(Userモデル)を作成すると、
下記の通りになる。

app/models/user.rb
class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
end

5行目の:validatableという記述が、
deviseにより自動的に設けられているバリデーションを指している。
バリデーションは下記の通りである。

email
  • 存在すること
  • 一意性であること
  • @を含むこと
password
  • 存在すること
  • 6文字以上128文字以下であること

学んだこと

上記バリデーションより、下記の挙動は検証しなければならない

  • email、passwordとpassword_confirmationが存在すれば登録できる
  • emailが空では登録できない
  • passwordが空では登録できない
  • passwordとpassword_confirmationが不一致では登録できない
  • 重複したemailが存在する場合は登録できない
  • emailは@を含まないと登録できない
  • passwordが5文字以下では登録できない
  • passwordが129文字以上では登録できない
0
0
1

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
0