Ruby on rails 强制用户在Desive中注销
我有一个应用程序,其中用户的会员资格已过期 我正在我的Ruby on rails 强制用户在Desive中注销,ruby-on-rails,ruby-on-rails-3,devise,Ruby On Rails,Ruby On Rails 3,Devise,我有一个应用程序,其中用户的会员资格已过期 我正在我的applications.rb文件中设置一个before_filter,在允许他们进入网站之前检查他们的会员资格是否处于活动状态 在my application.rb文件中: before_filter :check_account def check_account if user_signed_in? if current_user.account.expired flash[:error] = "Your
applications.rb
文件中设置一个before_filter
,在允许他们进入网站之前检查他们的会员资格是否处于活动状态
在my 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
我一直收到一个重定向循环错误。我猜这是因为正在调用的注销页面也在执行过滤前的,,但是如果我放置,除了=>[:users=>:sign\u 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
尝试按以下方式查询控制器/操作:
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
这应该可以消除重定向循环。为destroy\u user\u session\u path编写代码。是的,请将destroy代码放在此处该代码来自Desive gem-我将尝试找到它并将其添加到问题中。我添加了代码-但这是在gem中找到的,我真的不想编辑它。我认为这与过滤器和正确的调用方式有关。我认为你最好阻止他们完全登录,而不是在登录后立即将他们踢出。请参阅基本模式。谢谢Erez-效果很好。我注意到了一个后续问题,但我将把它放在另一个问题中。