2

I have a problem, i need create 3 type of users with devise. these users have different fields. I thought about creating a table but would have many blank fields.

any recommendations? I'm very confused. I need a tutorial :)

Thanks friends.

2 Answers2

2

You are looking for something called Single Table Inheritance. Basically you create one user model with devise which has a column "type" which is a string and you create sub models, like

class Admin < User end

Class CMS < User
end

etc....

Also, put all the common attributes in the User model

Look at these links for an in-depth explanation. STI is the solution. That much is sure

http://samurails.com/tutorial/single-table-inheritance-with-rails-4-part-1/

devise and multiple "user" models

Unique IDs between Users and Admins with Devise Rails

Rails 4 Devise Multiple User Models STI

Stackoverflow ppl has already dealt with STI extensively!

Hope these helps!

Community
  • 1
  • 1
Ravi Sankar Raju
  • 2,850
  • 3
  • 18
  • 16
1

Use STI mechanism... or you can separate all tables with use of devise

Jiggs
  • 518
  • 7
  • 22