blob: ce89f57a73bf9a6e5354657972a1dce13f4d89e4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# frozen_string_literal: true
module Organizations
class Organization < ApplicationRecord
DEFAULT_ORGANIZATION_ID = 1
scope :without_default, -> { where.not(id: DEFAULT_ORGANIZATION_ID) }
before_destroy :check_if_default_organization
validates :name,
presence: true,
length: { maximum: 255 }
validates :path,
presence: true,
'organizations/path': true,
length: { minimum: 2, maximum: 255 }
def self.default_organization
find_by(id: DEFAULT_ORGANIZATION_ID)
end
def default?
id == DEFAULT_ORGANIZATION_ID
end
def to_param
path
end
private
def check_if_default_organization
return unless default?
raise ActiveRecord::RecordNotDestroyed, _('Cannot delete the default organization')
end
end
end
|