Sanity check my Rails "Roles and Users" approach with Devise and Cancan -
been kicking 1 while now, , knows rails test theory (i'm new rails).
in (simplified) scenario, want manage list of users, of are, example, "paid" users, "free" users etc, , there straight "isa" relationship. i.e. paid user isa user, free user isa user etc
to reduce redundancy , keep semantically correct, want manage users in 1 table , use foreign-key correct "type" of user, can create role of correct type. e.g. instantiate user, id , store in user of correct type e.g. "paiduser" in "user_id" foreign-key. gives me ability store specific metadata want store against them, , don't have have 1 table ("users") every field every type of user.
this sort of feels confusion of roles , types of users. question is, using approach above going make life difficult? there accepted approach in rails i'm missing? i'm using devise , have removed routes except /users/ thinking pass "type" argument, , use type create corresponding "real" type of record @ same time user. bad practice too?
thanks in advance
what you're doing sounds fine, honest unless have lot of these different properties between user types put them in same table. it's not big deal have couple of blank columns here , there, when saves having whole load of difficult stuff. if starts seem unwieldy can worry - still easy change. potentially use single table inheritance give different user types own class inherits base user
class, take care of authentication etc.
if go more complex harder unravel if turns out wrong if start simple. if go multi-table approach make sure name them sensibly. go paiduserprofile
etc.
Comments
Post a Comment