* Use constant for type_of_user * Add comment for clarity * Remove legacy inline styles * Move comment above the render
17 lines
551 B
Ruby
17 lines
551 B
Ruby
class OrganizationMembership < ApplicationRecord
|
|
belongs_to :user
|
|
belongs_to :organization
|
|
|
|
USER_TYPES = %w[admin member guest].freeze
|
|
|
|
validates :user_id, :organization_id, :type_of_user, presence: true
|
|
validates :user_id, uniqueness: { scope: :organization_id }
|
|
validates :type_of_user, inclusion: { in: USER_TYPES }
|
|
|
|
after_create :update_user_organization_info_updated_at
|
|
after_destroy :update_user_organization_info_updated_at
|
|
|
|
def update_user_organization_info_updated_at
|
|
user.touch(:organization_info_updated_at)
|
|
end
|
|
end
|