私は宝石のデバイスを使用しています。そして、デバイス登録コントローラーをオーバーライドし、すべてがうまくいきましたが、問題は保存後のリダイレクトパスです。私がしたいのは、ユーザーが保存した後、profile_path にリダイレクトすることですが、プロファイル パスにリダイレクトする前にユーザーがサインインする必要があります。どうすれば解決できますか?ここに私の登録コントローラがあります:
class RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
@user= User.new(params[:user])
if @user.save
redirect_to profile_path, notice: 'User was successfully created.'
else
render action: "new"
end
end
def update
super
end
end
これは、サインアップしてサインインした後のパスを制御するアプリケーション コントローラーです。
class ApplicationController < ActionController::Base
protect_from_forgery
def after_sign_in_path_for(resource)
if request.path !~ /^\/admins\//i
resource.sign_in_count <= 1 ? '/profile' : root_path
end
end
end
登録コントローラーをオーバーライドする前に、サインアップ後のリダイレクトはうまくいきました。誰かが助けてくれたら本当にうれしいです。ありがとう。