overriding devise after_sign_up_path_for not working

后端 未结 7 1437
刺人心
刺人心 2020-12-15 17:48

In routes i have the root-path pointing \"home#index\" but when i try to override that with after_sign_up_path_for keeps redirecting me to the root path when I

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 18:12

    If using OmniAuth custom callback controllers with Rails 5.2:

    In my particular case, the after sign up path was not working: but I was using OmniAuth with a custom callback controller, which was invoking the after_sign_in_path_for rather than the former:

    def google_oauth2 @user = User.from_omniauth(request.env["omniauth.auth"])

    if @user.persisted?
      # Here's the guilty line your honour:
      sign_in_and_redirect @user, event: :authentication #this will throw if @user is not activated
      set_flash_message(:notice, :success, kind: "Google") if is_navigational_format?
    else
      session["devise.google_oauth2_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
    

    end

    ........And the sign_in_and_redirect path redirects to the after_sign_in_path_for method. So I generated a new devise controller for sessions and simply overrode that method. problem solved!

提交回复
热议问题