deviseで面白い機能(プレビュー機能)を見つけたのでメモ

110
_110365
Published in
2 min readMar 13, 2020

ユーザー認証のdeviseで

ユーザー登録→メールで本人確認(deviseのconfirmableモジュール)→パスワード設定画面遷移・・・というのをやりたくて調べていたら以下のWikiを発見。

The website may provide a few ways to confirm the account and, in the mean time, allow the “pending” user to use all of the website features, as a “service preview”; or it could limit the features scope. This could prove useful for SaaS, for instance. If the confirmation is not performed within a certain time range, the account is disabled somehow.

アカウントを仮登録(お試し利用)状態にして、一定期間サービスの全機能または一部機能を使えるようにすることができるみたいです。

config/initializer/devise.rb内で期間を設定すればOK。

# devise ver2.0以上
config.allow_unconfirmed_access_for = 7.days
# ちなみにそれ以前のバージョンは
config.confirm_within = 7.days
# お試し期間を設けない
config.allow_unconfirmed_access_for = 0
# 本人確認しなくてもログイン可能(お試し期間が無制限)
config.allow_unconfirmed_access_for = nil

一部機能を制限するにはどうやるんだろう?
結構やりたい場面はありそうだなと思いました。

--

--