gpt4 book ai didi

ruby-on-rails - 强制用户在 Devise 中注销

转载 作者:行者123 更新时间:2023-12-02 08:40:42 25 4
gpt4 key购买 nike

我有一个应用程序,其中用户的成员(member)资格已过期。

我正在我的 applications.rb 文件中设置 before_filter,以在允许他们进入网站之前检查他们的成员(member)资格是否有效。

在我的 application.rb 文件中:

before_filter :check_account

def check_account
if user_signed_in?
if current_user.account.expired
flash[:error] = "Your account is expired. Please contact Navanti for renewal."
redirect_to destroy_user_session_path
end
end
end

我不断收到重定向循环错误。我猜测这是因为被调用的注销页面也在执行 before_filter ,但是如果我放置 except => [:users => :sign_out]它仍然抛出循环错误。

感谢您的帮助。

<小时/>

请求的设计方法:

# DELETE /resource/sign_out

def destroy
redirect_path = after_sign_out_path_for(resource_name)
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
set_flash_message :notice, :signed_out if signed_out && is_navigational_format?

# We actually need to hardcode this as Rails default responder doesn't
# support returning empty response on GET request
respond_to do |format|
format.any(*navigational_formats) { redirect_to redirect_path }
format.all do
head :no_content
end
end
end

最佳答案

尝试通过以下方式查询 Controller /操作:

def check_account
return if params[:controller] == "devise/sessions" && params[:action] == "destroy"
if user_signed_in?
if current_user.account.expired
flash[:error] = "Your account is expired. Please contact Navanti for renewal."
redirect_to destroy_user_session_path
end
end
end

这应该可以消除您所遇到的重定向循环。

关于ruby-on-rails - 强制用户在 Devise 中注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12695037/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com