Sha256: 44c3a37dbae41b06f5573dc467b256307d304efd410df9e043378ebe21468e30
Contents?: true
Size: 642 Bytes
Versions: 22
Compression:
Stored size: 642 Bytes
Contents
class User < ApplicationRecord # Rolify needs to be called before assigning default role due to a bug in Rolify # see: https://github.com/RolifyCommunity/rolify/issues/518#issuecomment-1218705389 rolify after_create :assign_default_role devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable validate :must_have_role, on: :update def assign_default_role self.add_role(:user) if self.roles.blank? end def role_names roles.distinct.pluck(:name) end def must_have_role if self.roles.blank? errors.add(:roles, "User must have at least one role") end end end
Version data entries
22 entries across 22 versions & 1 rubygems