LoginSignup
0
2

More than 5 years have passed since last update.

簡単に認証機能を実装できるgem devise

Posted at

railsのコードによく出てくるdeviseとはなんぞやと言うのを調べていたら
かなり便利なものだったのでまとめてみました。

sample.rb
class Sample < ActiveRecord::Base
  devise :database_authenticatable, 
         :recoverable, :rememberable, :trackable, :validatable, :lockable
end

このように書くことで認証機能を作ることができるそうです。

具体的に中身を見ていきます。

機能一覧

database_authenticatable
データベースに保存されたパスワードの確認。暗号化も兼ねている。

recoverable
パスワードをリセット

rememberable
ログインしていることを覚えせせる機能
ログイン画面の下の方にチェックボックスを押すと、ずっとログイン状態に

trackable
サインイン回数、時間など、ユーザーの分析に必要なデータを保存

validatable
パスワードの長さなどを自動でバリデーションしてくれる

lockable
ログインに何度も失敗すると、アカウントをロックできる

他にも色々機能はあるようです。

参考記事
もっと詳しい手順を見たい方はこちらへ

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