Suppose I want to create a model User without self registration. I have created the User model and added the following line
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
in my routes.db
file I skip registration
devise_for :users, skip: :registrations
When I run rake routes
registration paths disappear.
However, I can get the same configuration simply removing :registerable
from the User model instead of adding `skip: :registrations.
So the question: what is the main difference between the two ways of removing self-registration? Which one is more preferable?
If you are not interested in user registration, both options give you the same result, although I prefer to remove the registerable
module from the User model to avoid loading it and not use it at all.
You can see the devise
method in the next link, so you can understand what you're avoiding by not loading the module:
https://github.com/plataformatec/devise/blob/master/lib/devise/models.rb#L77
On the other hand, if you are interested in user registration through any subclass (say buyer or seller, using STI) not the class itself (user), you need the registerable
module on User model and something like that on routes:
devise_for :users, skip: :registrations
devise_for :buyers, only: :registrations
devise_for :sellers, only: :registrations
I hope it helps.
There can be other reasons for wanting to remove the registration routes - eg. making your own routes that point to the Devise controllers.
If you really want to disable site registration, then remove :registerable
from your User model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With