-
Notifications
You must be signed in to change notification settings - Fork 5.5k
How To: Disable user from destroying their account alternative method
Naofumi Kagami edited this page Sep 7, 2022
·
2 revisions
How To: Disable user from destroying their account describes a way to disable users from destroying their accounts by redefining routes for the registrations controller.
You can also achieve a similar result by overriding the paths in config/routes.rb
. Here we take advantage of the fact that the routes.rb
file is read from top to bottom, and will use the first matching route. Below, I am routing to the Rack application contained in the lambda.
config/routes.rb
delete '/users', to: ->(env) { [404, {}, ['']] }
devise_for :users
You can use this method to disable any other routes in Devise.
One drawback of this method is that the original route will still show up in bin/rails routes
but if this does not bother you, then I think this is a simpler way to disable routes.