6

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.

James Chevalier
  • 10,604
  • 5
  • 48
  • 74
Rails beginner
  • 14,321
  • 35
  • 137
  • 257

2 Answers2

8

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/*.

mkirk
  • 3,965
  • 1
  • 26
  • 37
1

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

codevoice
  • 474
  • 3
  • 6
  • What should i then do in the view? Will there not by 2 login in pages? <% if company_signed_in? %> Signed in as <%= current_company.email %> . Not you? <%= link_to "Sign out", destroy_company_session_path %> <% else %> <%= link_to "Sign up", new_company_registration_path %> or <%= link_to "sign in", new_company_session_path %> <% end %> I only want 1 login page – Rails beginner Dec 29 '10 at 20:02
  • yup something like this- you will have `current_companyz and `current_worker` and so on ... check `rake routes | grep session` to find out paths – codevoice Dec 29 '10 at 20:09
  • How do i make 1 login page where you can login as worker and company. I dont want them to be seperate. – Rails beginner Dec 29 '10 at 20:10
  • you should make your own login page – codevoice Dec 29 '10 at 20:15
  • Is there i way that i can have i can make a tabel Users wish stores all login informationen. Instead of haveing 2 separate tabels that have columns for the login information? – Rails beginner Dec 29 '10 at 20:45