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 trialSteve Christie
9,509 Pointsuser with sub user authentication
I'm trying to build a rails app using a custom authentication system(like the one Michael Hartl uses in his Ruby on Rails Tutorial), but where the primary user can create sub users. For example, the primary user would sign up for a service(and pay!) but then create sub users. Each sub user would have their own user name and password. Just like a Treehouse Group account.
I've tried to code it on my own, but I'm running into several issues and was looking to see if anyone knows of a book, article or tutorial that would explain how it's done. Here's a link to the gihub with my first stab at it: https://github.com/stevejc/buyer
Jason/Jim., if nothing out there, maybe a possible topic for a Treehouse Workshop.
2 Answers
Jason Seifer
Treehouse Guest TeacherHey Steve Christie you're off to a good start. On your user model I'd change the "has_one :account" association to a belongs_to association. Generally you'll have an account model (like you do) that has an account administrator role of some sort and you keep track of users based on the account id. It's a bit beyond the scope of a forum post but Railscasts has a great post on this at http://railscasts.com/episodes/388-multitenancy-with-scopes.
Steve Christie
9,509 PointsThanks Jason. Ah it's called multitenancy. Thanks for the link. I'll definitely checkout the railscast. Empowered the right term, I also found a book by Ryan Bigg, Multitenancy with Rails that walks through the coding of a multi tenant site.