条件 X が満たされた場合に、ログインしているユーザーに特定の controller#action へのアクセスのみを許可する最良の方法は何でしょうか?
- たとえば、ユーザーが自分のアカウントを非アクティブ化した ( user.is_deleted == true )
- ユーザーがログインした場合、ユーザーを /reactivate にリダイレクトしたい
- ユーザーが /profiles /search などの他の URL を試した場合、/reactivate にリダイレクトする必要があります。
ログインとログアウトの方法を除いて、applicationcontrollerでbefore_filtersを試しましたが、他のアクションと正しく機能しないため、これを行うためのクリーンな方法を本当に探しています。誰か提案はありますか?
現在、私はを使用しています
def after_sign_in_path_for(resource)
@user = User.where(:id => current_user.id).first
if @user.is_deleted == true
"/reactivate"
end
終わり
しかし*これはユーザーログインでのみ機能します* その後、/ home / searchなどのようなことを行うことができるので、アプリを「ロックダウン」したいと思います。カスタム コードの代わりに、can のようなものでこれを行う必要があるのではないかと考えました。
これを行うための作業中の保守可能なクリーンな方法を知っていますか?
編集:
このようなことをしました(乱雑で壊れていることがわかります)
def welcome_redirect
if user_signed_in?
if not current_user.welcome == 0
if not params[:controller] == "home" && params[:action] == "welcome"
if not params[:controller] == "modal"
if not params[:controller] == "profiles"
redirect_to profiles_path
end
end
end
end
end
end
編集2:
これはうまくいくようです:
def ensure_account_not_deleted
if user_signed_in?
@user = User.where(:id => current_user.id).first
if params[:controller] != "users" && params[:action] != "reactivate" && @user.is_deleted == true
redirect_to '/reactivate'
end
end
end
- フィルターの前の別の値がいくつかの値を台無しにしていたため、これが機能しませんでした。このソリューションにつながる提案のすべてthx *