LoginSignup
2
0

More than 3 years have passed since last update.

devise ユーザー登録場面でパスワード文字数を指定する方法

Posted at

deviseを用いsign_up,sign_in機能を実装しています。
よくある、パスワードの文字数指定について、どこに何を追記すべきかメモしておきます。

環境
rails (5.2.4.2)

userモデルの:validatableに続けて、password_length: (指定文字数)..128と
記載すればOKです。
※128の意味は勉強中

7文字以上としたい場合は以下のようになります。

user.rb
class User < ApplicationRecord
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable,  :validatable, password_length: 7..128

  validates :nickname, :password, :email, :last_name, :first_name, :ruby_last_name, :ruby_first_name, :birthdate, presence: true
  has_many :products
  has_one :ship_address
end

他にもいろいろと方法はあるようですが、比較的わかりやすいもののメモでした。

参考にさせていただいた記事
https://qiita.com/hirokihello/items/862284c60429be5e01cd

誤認識等あればご指摘いただければ幸いです🙇‍♂️

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