0

私は宝石のデバイスを使用しています。そして、デバイス登録コントローラーをオーバーライドし、すべてがうまくいきましたが、問題は保存後のリダイレクトパスです。私がしたいのは、ユーザーが保存した後、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

登録コントローラーをオーバーライドする前に、サインアップ後のリダイレクトはうまくいきました。誰かが助けてくれたら本当にうれしいです。ありがとう。

4

1 に答える 1

0

createメソッドでユーザーにサインインする必要があります。

if @user.save
  sign_in(resource_name, resource)
  current_user = @user # !! now logged in
  redirect_to profile_path, notice: 'User was successfully created.'
else

元のcreateメソッドDevise::RegistrationsControllerを見て、これがどのように機能するかを確認できます。

于 2013-09-24T15:44:58.857 に答える