Redirect User to Signup

前端 未结 5 978
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 20:47

Using before_action :authenticate_user! to check if user logged in. But it sends users to login instead of signup.

Tried different

5条回答
  •  灰色年华
    2021-02-05 21:06

    Devise uses warden for authentication. Thus to override the whole behavior you have to override the way devise asks it to handle authentication failures.

    Create a class that extends Devise::FailureApp

    class RedirectToSignUp < Devise::FailureApp
      def redirect_url
         new_user_registration_url
      end
    
      def respond
        if http_auth?
          http_auth
        else
          redirect_to new_user_registration_url
        end
      end
    end
    

    Add this to your devise initializer config/initializers/devise.rb

    config.warden do |manager|
      manager.failure_app = RedirectToSignUp
    end
    

    I believe this will solve your problem and will redirect you to the page you were at since you are overriding only the redirect route.

提交回复
热议问题