Let me confuse the water a bit. I prefer this through the Role table and the UserRole connection UserRole . This way I can define more than one role without adding another column / table in db.
class User has_many :user_roles has_many :roles, :through => :user_roles def role?(role) role_names.include? role end def role_names @role_names ||= self.roles.map(&:name) end def role=(role) self.roles << Role.find_or_create_by_name(role) end end class UserRole # integer: user_id, integer: role_id belongs_to :user belongs_to :role end class Role # string: name has_many :user_roles has_many :users, :through => :user_roles end
tihom source share