0

私はdeviseを使用しており、ユーザーをif seller_disabled_paypal_permissions != nil自分の特定のページにリダイレクトする必要がありますapplication_controller.rb

このコードはapplication_controller.rbにあります

class ApplicationController < ActionController::Base
 before_filter :bad_sellers
 #more code
 .
 .
 .
 private
   def bad_sellers
    if user_signed_in?
     redirect_to requirements_to_sell_user_path, :alert => t('.error') if current_user.seller_disabled_paypal_permissions != nil
     return false
    end
   end
end

しかし、エラーが発生します:

エラー310(net :: ERR_TOO_MANY_REDIRECTS):リダイレクトが多すぎました。

どうすればいいですか?

4

4 に答える 4

0

問題の修正:

の上applicatio_controller.rb

class ApplicationController < ActionController::Base
 protect_from_forgery
 before_filter :bad_sellers
 #code here
 #code here
 def bad_sellers
  if user_signed_in? && !(current_user.seller_disabled_paypal_permissions.nil?)
   redirect_to requirements_to_sell_user_path(current_user), :alert => t('.error')
  end
 end
end

オンusers_controllers.rbusers_controllersの子application_controller

class UsersController < ApplicationController
 skip_before_filter :bad_sellers, :only => [:requirements_to_sell] #parent filter on application_controller.rb

 def requirements_to_sell
  #more code
  #more code
 end

end
于 2013-01-17T16:09:29.110 に答える
0
private
   def bad_sellers
    if user_signed_in? && !(current_user.seller_disabled_paypal_permissions.nil?)
     redirect_to root_path, :alert => t('.error')
    end
   end

a から明示的に値を返したことがないbefore_fiterので、それが最初の推測です。

あなたの問題は、あなたがこの動作を作成したことでApplicationControllerあり、ルートパスも継承するコントローラーであるApplicationControllerため、無限のリダイレクトループに陥ることに賭けています。

次のようなものが必要です。

before_filter :bad_sellers, :except => [:whatever_your_root_path_action_is]
于 2013-01-16T19:19:56.197 に答える
0

再帰的になる可能性があるようです。root_path もフィルターの前にこれを呼び出しますか? その場合、これを呼び出さない方法を見つけたいと思うでしょう。調べるskip_before_filter

また、「false を返す」必要はありません。

于 2013-01-16T19:57:09.517 に答える
0

条件付きリダイレクトがある場合は、returnRails が他のリダイレクトを認識しないようにする必要があります (それ以上のリダイレクト方法はわかりません)。

あなたの例に従って:

def bad_sellers
  if user_signed_in?
    if !current_user.seller_disabled_paypal_permissions.nil?
      return redirect_to root_path, :alert => t('.error')
    end
  end
end
于 2013-01-16T19:23:06.770 に答える