Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tackle different user types with Devise

I have 2 types of Users. A Company and a Worker.

How do I manage it in devise where I have only 1 User?

I want to create 2 registration pages for Company and Worker, but I only want 1 table which stores user information such as Users.

like image 258
Rails beginner Avatar asked Dec 29 '10 19:12

Rails beginner


1 Answers

I'd comment on codevoice's ample response, but I don't have enough rep yet.

From documentation that codevoice linked to:

If you have more than one role in your application (such as "User" and "Admin"), you will notice that Devise uses the same views for all roles. Fortunately, Devise offers an easy way to customize views. All you need to do is set "config.scoped_views = true" inside "config/initializers/devise.rb".

After doing so, you will be able to have views based on the role like "users/sessions/new" and "admins/sessions/new". If no view is found within the scope, Devise will use the default view at "devise/sessions/new". You can also use the generator to generate scoped views:

...

So it's possible to have one set of views for all devise models, just put them in devise/sessions/*.

like image 153
mkirk Avatar answered Oct 13 '22 00:10

mkirk