Multiple users with devise in the same model

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.

Upvotes: 2

Views: 1226

Answers (2)

Jiggs
Jiggs

Reputation: 528

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

Upvotes: 1

Ravi Sankar Raju
Ravi Sankar Raju

Reputation: 2958

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!

Upvotes: 2

Related Questions