diff --git a/app/models/budget.rb b/app/models/budget.rb index 4904f3923..c4fe62eeb 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -229,16 +229,4 @@ class Budget < ApplicationRecord slug.nil? || drafting? end - class Translation < Globalize::ActiveRecord::Translation - validate :name_uniqueness_by_budget - - def name_uniqueness_by_budget - if Budget.joins(:translations) - .where(name: name) - .where.not("budget_translations.budget_id": budget_id).any? - errors.add(:name, I18n.t("errors.messages.taken")) - end - end - end - end diff --git a/app/models/budget/group.rb b/app/models/budget/group.rb index 741040c78..71eebb308 100644 --- a/app/models/budget/group.rb +++ b/app/models/budget/group.rb @@ -39,19 +39,5 @@ class Budget def generate_slug? slug.nil? || budget.drafting? end - - class Translation < Globalize::ActiveRecord::Translation - delegate :budget, to: :globalized_model - - validate :name_uniqueness_by_budget - - def name_uniqueness_by_budget - if budget.groups.joins(:translations) - .where(name: name) - .where.not("budget_group_translations.budget_group_id": budget_group_id).any? - errors.add(:name, I18n.t("errors.messages.taken")) - end - end - end end end diff --git a/app/models/budget/heading.rb b/app/models/budget/heading.rb index 0221061d7..0e218d6fb 100644 --- a/app/models/budget/heading.rb +++ b/app/models/budget/heading.rb @@ -59,20 +59,5 @@ class Budget def generate_slug? slug.nil? || budget.drafting? end - - class Translation < Globalize::ActiveRecord::Translation - delegate :budget, to: :globalized_model - - validate :name_uniqueness_by_budget - - def name_uniqueness_by_budget - if budget.headings - .joins(:translations) - .where(name: name) - .where.not("budget_heading_translations.budget_heading_id": budget_heading_id).any? - errors.add(:name, I18n.t("errors.messages.taken")) - end - end - end end end diff --git a/app/models/budget/phase.rb b/app/models/budget/phase.rb index 5d28e65ab..56d125d1d 100644 --- a/app/models/budget/phase.rb +++ b/app/models/budget/phase.rb @@ -9,6 +9,17 @@ class Budget translates :summary, touch: true translates :description, touch: true include Globalizable + + class Translation + before_validation :sanitize_description + + private + + def sanitize_description + self.description = WYSIWYGSanitizer.new.sanitize(description) + end + end + include Sanitizable belongs_to :budget @@ -99,15 +110,5 @@ class Budget def in_phase_or_later?(phase) PHASE_KINDS.index(kind) >= PHASE_KINDS.index(phase) end - - class Translation < Globalize::ActiveRecord::Translation - before_validation :sanitize_description - - private - - def sanitize_description - self.description = WYSIWYGSanitizer.new.sanitize(description) - end - end end end