7
5

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 5 years have passed since last update.

devise でアカウントのステータスに応じてログイン不可にする

7
Posted at

例えば User モデルを使用している場合、以下のように active_for_authentication? メソッドをオーバーライドする

app/models/user.rb
  def active_for_authentication?
    super && status_enable?
  end

あと、メッセージを変更したい場合は以下のように inactive_message メソッドをオーバーライドする

app/models/user.rb
  def inactive_message
    status_enable? ? super : :status_disabled
  end

メッセージの文言は config/locale/devise.ja.yml に登録する(上記シンボルの部分に直接メッセージを書いても良い)

7
5
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
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?