From 9a15f3d160e242a1a258183fecab751c6902b4f7 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Mon, 25 Mar 2019 17:55:50 +0100 Subject: [PATCH] Remove Budget overrided translation class Since Globalize gem update to v5.2.0 we cannot override translations anymore in the same way that before the update. Milestone::Translation class removed in this commit were no longer loaded correctly when translation class is retrieved by translation_class method provided by Globalize. Here is the diff between both gem versions: https://github.com/globalize/globalize/compare/v5.0.0...v5.2.0diff-a1370b109e0dd567545b072bc6447b8fR51 This problem is not happening on test environment but is throwing an exception in other environments as it has not loaded the delegation definition inside our custom translation class. To fix this we added a new class method inside globalizable model concern to allow to define method delegation on translations classes from parent globalizable classes when needed without having to override Translation classes. Another way to properly load our custom Milestone::Translation class is to place it inside parent model class. --- app/models/budget.rb | 12 ++++++++++++ app/models/budget/translation.rb | 11 ----------- 2 files changed, 12 insertions(+), 11 deletions(-) delete mode 100644 app/models/budget/translation.rb diff --git a/app/models/budget.rb b/app/models/budget.rb index 28fb8c5ca..ae589302f 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -6,6 +6,18 @@ class Budget < ActiveRecord::Base translates :name, touch: true include Globalizable + class 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 + CURRENCY_SYMBOLS = %w(€ $ £ ¥).freeze before_validation :assign_model_to_translations diff --git a/app/models/budget/translation.rb b/app/models/budget/translation.rb deleted file mode 100644 index 1f3d93ea1..000000000 --- a/app/models/budget/translation.rb +++ /dev/null @@ -1,11 +0,0 @@ -class Budget::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