How to Remove/Disable Sign Up From Devise

前端 未结 6 1541
余生分开走
余生分开走 2021-02-05 02:56

I\'m trying to remove/disable the user/sign_up path from Devise. I\'m doing this because I don\'t want random people gaining access to the application. I have it p

6条回答
  •  渐次进展
    2021-02-05 03:22

    Redirecting from controller

    I solved this issue by redirecting /sign_up to /sign_in from the controller, while preserving the functionality of editing user info. For instance:

    In controllers/users/registrations_controller.rb

    # GET /resource/sign_up
      def new
        redirect_to new_user_session_path and return
        super
      end
    

    In routes.rb, I pointed registrations resource to this controller:

      devise_for :users, controllers: {
        sessions: 'users/sessions',
        registrations: 'users/registrations'
      }
    

    So whenever users visit route /sign_up, it'll redirect them to /sign_in. Just remember to use and return after the redirection to prevent multiple render/redirect

提交回复
热议问题