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.
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/*.
first prepare models then
just register devise_for
both models
devise_for :companies
devise_for :workers
in routes
here you have example: devise manual github
精彩评论