Using traco with a legacy rails system
professor opened this issue · 0 comments
professor commented
I was trying to solve something similar to @Kinaan in #32
We have a long lived Rails application with many tables and many columns and other business units that write sql queries against our database. Renaming English columns (:name to :name_en) would break many of our external dependencies.
I'm considering a different approach and offer it here if it is helpful to anyone else.
Step 1, we add in :name_en which is what traco will treat as the source of truth for the data
Step 2, we make sure that :name is in-sync with :name_en for all of our external dependencies.
class Product < ActiveRecord::Base
translates :name, :description
before_save do
write_attribute(:name, name_en)
write_attribute(:description, description_en)
end
before_update do
write_attribute(:name, name_en)
write_attribute(:description, description_en)
end
end
Just realized that for ActiveAdmin, we'll want to disable editing name
and edit name_en
instead.