Yar*_*rin 2 ruby-on-rails devise
我有一个控制器过滤器,如果他们的帐户过期,应该注销用户,但我无法找到一个简单的方法来做到这一点.
我试过了:
if user_signed_in? && current_user.status == 'expired'
redirect_to destroy_user_session_path
end
Run Code Online (Sandbox Code Playgroud)
但上述方法不起作用,因为Devise想要在注销路径上执行DELETE操作,因此您不能只重定向到它.
active_for_authentication?
在对用户进行身份验证并在每个请求中,Devise通过调用model.active_for_authentication?来检查您的模型是否处于活动状态.其他设计模块会覆盖此方法.例如,:确认覆盖.active_for_authentication?如果您的模型已确认,则仅返回true.
你自己覆盖这个方法,但是如果你这样做,别忘了给super打电话:
def active_for_authentication?
super && special_condition_is_valid?
end
Run Code Online (Sandbox Code Playgroud)