How to Remove/Disable Sign Up From Devise

前端 未结 6 1273
余生分开走
余生分开走 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

    Solution to removing sign_up path from Devise

    Enter the following at the beginning of routes.rb

    Rails.application.routes.draw do
      devise_scope :user do
        get "/sign_in" => "devise/sessions#new" # custom path to login/sign_in
        get "/sign_up" => "devise/registrations#new", as: "new_user_registration" # custom path to sign_up/registration
      end
    

    ...After the statement above, add the following below in routes.rb

    devise_for :users, :skip => [:registrations] 
      as :user do
      get 'users/edit' => 'devise/registrations#edit', :as => 'edit_user_registration'
      put 'users' => 'devise/registrations#update', :as => 'user_registration'
      end
    

    This will remove/disable the user/sign_up path for Devise without breaking edit_user_registration_path

    Restart your rails server and it should work.

提交回复
热议问题