0

This is a Rails app for a school. I'm using Devise for user accounts. So far each user has a .role of admin, teacher or student which restricts what the user can access and contribute in the app. I'm using user.email to log in. All is working great so far.

Now I've realized that I have a problem with sibling accounts. The unique user.email used for logging in is actually the parent's email address (since the students are minors) and now I have to account for a parent with two or more children who are students. I obviously can't have a student account for each child and use the same email address because it has to be unique (and I do want to keep the requirement in the validation).

Given that I already have a large chuck of the app done, what would be a nice DRY way to account for this situation?

I've searched this site and others but not really found anything that accounts for this situation.

One way I thought would be to change the role in the User model to parent and then have a separate Student model . A user with the role of parent could then has_many :students but this doesn't sit well with me.

Any general ideas/concepts would be appreciated, as would any pointers to articles or gems that would help me with this.

Dan Weaver
  • 711
  • 8
  • 20

1 Answers1

0

I don't know if it's the best way, but one approach would be to append a sibling-unique identifier to the name portion of the parent's email address for all student email addresses. You could do it in such a way that it could be stripped off when you wanted the "real" email address. There's actually some precedent for this kind of approach, per http://www.plankdesign.com/blog/2013/06/testing-infinite-unique-email-addresses-with-gmail/.

Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106
  • That's interesting. It would certainly be easy to implement without much disruption to my models but I'm not sure it would be very user-friendly. I'll give it a go on a branch and see how it feels. – Dan Weaver Aug 13 '13 at 05:33
  • You wouldn't have to do this for the first child of any given parent, only the second and beyond, at the cost of some additional code for email generation. – Peter Alfvin Aug 13 '13 at 15:23
  • Are you suggesting parents have 2 different sets of log in credentials and log into 2 separate accounts? Ideally I'd like a parent to log in and see details for all of their children in one dashboard. I've been advised this will affect about 10% of parents. – Dan Weaver Aug 13 '13 at 23:08
  • I actually had assumed that you wanted separate accounts for each student. If you just want one account, then it seems to me that you're really talking about a *parent* account and student is a separate abstraction. – Peter Alfvin Aug 13 '13 at 23:31
  • I think you're right. I need to forget the idea of getting this to work within my current models and look at a separate Student account. Thanks. – Dan Weaver Aug 14 '13 at 00:02
  • I'm accepting your answer above because it does answer my question, but since my question was malformed it doesn't actually solve my problem! :) – Dan Weaver Aug 14 '13 at 00:03