2

デバイスをインストールし、正常に動作していますが、サインインがリダイレクトされます。ユーザーがアプリの任意のページからサインインすると、Devise はユーザーを同じページにリダイレクトするのではなく、ホームにリダイレクトします。私はdeviseのHow_toソリューションを実装しようとしましたが、助けにはなりませんでした。

私はapplication_controllerに書きました:

def after_sign_in_path_for(resource)
 current_user_path 
end

しかし、それはエラーを出します:

undefined local variable or method `current_user_path' for #<Devise::SessionsController:0xaeacc34>

私が書くとき:

def after_sign_in_path_for(resource)
 current_user_path 
end

それは与えます :

undefined method `user_url'

この問題の解決策は何ですか? これを助ける体はありますか?

4

2 に答える 2

1

どのシーン (エラーまたは成功) で別の場所にリダイレクトする必要がありますか? 通常 after_sign_in_path_for は、ユーザーが正常にログインした後に使用されます。それで:

デバイスのデフォルト機能をオーバーライドしていない場合は、以下のコードを使用して特定のカスタム ページにコントロールを移動します。current_userこのアクションでもアクセスできます。

def after_sign_in_path_for(resource)
    scope = Devise::Mapping.find_scope!(resource)
    scope_path = :"#{scope}_root_path"
    respond_to?(scope_path, true) ? send(scope_path) : root_url
end

更新: 別の例は次のとおりです。

 def after_sign_in_path_for(resource_or_scope)
    current_user.admin? ? dashboard_admin_home_index_path : current_user.sign_in_count >= 1 ? "/home/dashboard" : "/#{current_user.role}/dashboard"
  end
于 2013-03-28T08:38:34.613 に答える