Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

skip: registration vs remove :registerable

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?

like image 731
fade2black Avatar asked Mar 14 '14 12:03

fade2black


2 Answers

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.

like image 173
backpackerhh Avatar answered Nov 18 '22 13:11

backpackerhh


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.

like image 44
sevenseacat Avatar answered Nov 18 '22 14:11

sevenseacat