I’ve implement polymorphic users in an app I’m developing. To avoid clunky method chains when accessing the associated object (in my case an account) I’m using a helper method…
def current_account current_user.account end
So that I can call
current_account.foo rather than
current_user.account.foo. This has served the purpose so far but for some reason it doesn’t feel right to me.
Besides authorization, I imagine that 9 times out of 10 the behaviour I want on
current_user will be implemented by the account object, but the behaviour is only on
Account because of the polymorphic implementation, it’s really extending the behaviour of
I’d maybe feel a bit more comfortable if the models that a polymorphic user comprised of were called something like
Identity(for the auth) and
User(for the behaviour) rather than user and account, but I’m using the conveniences of Clearance rather than rolling my own.
Another option I can see is to pass in the
Account object into Clearance’s
sign in helper, and delegate the methods that clearance requires of
I just wanted to throw this out there to gain some other perspectives and opinions, and to see if anybody has resolved a similar issue. That is of course if it is an issue, I could have just become fixated on something that really shouldn’t be of concern.
Looking forward to hearing some thoughts,