-
Notifications
You must be signed in to change notification settings - Fork 2
/
theme.rb
39 lines (28 loc) · 843 Bytes
/
theme.rb
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
class Theme < ApplicationRecord
scope :primary, -> { where('parent_id IS NULL') }
belongs_to :parent, class_name: 'Theme', optional: true
has_many :proposals, as: :collection
has_many :assessments, -> { distinct }, through: :proposals
has_many :themes, foreign_key: 'parent_id'
has_many :fund_themes, dependent: :destroy
has_many :funds, through: :fund_themes
has_many :criteria, -> { distinct }, through: :funds
has_many :priorities, -> { distinct }, through: :funds
has_many :restrictions, -> { distinct }, through: :funds
validates :name, :slug, uniqueness: true
validates :classes, presence: true
before_validation :set_slug
def primary_color
nil
end
def secondary_color
nil
end
def to_param
slug
end
private
def set_slug
self[:slug] = name.parameterize
end
end