Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Devise & single table inheritence

Hi everyone,

I'm looking for some advice from anyone who has had some experience with the following:

I have an existing app with two "user types" that I would like to join using single table inheritance to a Devise user model.

The goal is simply to keep the existing functionality and relationships between the current models while making it easier to create and manage user accounts.

Is this how you would go about this task? I am interested to hear other options in the interest of furthering my RoR education.

Thank you.

4 Answers

Nick Fuller
Nick Fuller
9,027 Points

Nothing wrong with this. I used STI with Devise when I had to maintain the concept of an Employee and a Contractor. Both user types were logging into the system, and both user types had a similar base set of attributes (first_name, last_name, email, password_digest etc. etc.) but obviously an employee and a contractor will end up requiring different subsets of data. It all depends on the application.

I think if you have 2x existing models and you're interested in building in STI... then it will be more difficult than starting with a User model and subclassing it off with an Employee model. But, as programmers, we love challenges :)

Hi Nick, thanks so much for the quick response. That was really helpful, I can continue with some confidence now haha.

I have seen your comments around the forum and always find them very helpful and friendly, thanks so much for helping people out.

Nick Fuller
Nick Fuller
9,027 Points

Absolutely Pat! Glad to help!

Hey Nick just another thought.

Once devise is installed and users sign up under the "devise user" model, how to you then go about specifying the appropriate account type?

There seems to me no issue with taking users with an existing account type and moving them to the "user" model using STI. But I don't get the logic of doing the reverse...

any thoughts?

Never mind I figured it out! Thanks again