Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to model different users in Rails

Question

I have a User model with authorisation and authentication logic built.

Now I realise I have three different types of users. I want to store different information about each of them.

What is the best way to handle this in Rails?

Thoughts based on current reading

I've looked at STI but from what I've read feel it is inappropriate because I'll end up with a lot of NULL fields in my database.

Ideally I'd like to not duplicate the authentication / authorisation logic for each of the three user types.

Each user will also have different functionality within the application.

like image 648
cmd Avatar asked Nov 12 '22 11:11

cmd


1 Answers

You can try using polymorphic associations and creating table users with data that all types of users have and putting other data in seperate tables. Railscast epizode covering this topic.

like image 106
Konrad Gadzina Avatar answered Nov 15 '22 05:11

Konrad Gadzina