7

ユーザーが期限切れのメンバーシップを持っているアプリがあります。

私はbefore_filter自分のapplications.rbファイルに を設定して、サイトに入れる前にメンバーシップがアクティブであることを確認する作業を行っています。

私の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
4

1 に答える 1

7

次の方法でコントローラー/アクションを照会してみてください。

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

これにより、現在発生しているリダイレクトループが解消されます。

于 2012-10-02T18:17:37.410 に答える