简体   繁体   中英

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.

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!

使用STI机制...或者您可以使用devise分隔所有表

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM