I’m developing a new Rails app and it’s required to have 3 different types of users, lets say user A, user B and user C.
All of them have different properties and different Models depend on each one, but they should also share some of them, like the username property so its possible to refer to the profile via URL (Like on facebook or twitter), or select user’s country, city, etc.
I was wondering if a polymorphic association would be the best approach, creating A, B and C models independently and sharing a Global User model.
class GlobalUser < ActiveRecord::Base belongs_to :userable, polymorphic: true end class UserA < ActiveRecord::Base has_one :user, as: :userable end class UserB < ActiveRecord::Base has_one :user, as: :userable end class UserC < ActiveRecord::Base has_one :user, as: :userable end
I’m kind of new to Rails and I’ve never required this type of association before, so any help or suggestion provided will be very helpful.
Is there a better way to do this?
Thanks everybody in advance and sorry for my English