Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using traco with a legacy rails system #50

Open
professor opened this issue Jan 5, 2022 · 0 comments
Open

Using traco with a legacy rails system #50

professor opened this issue Jan 5, 2022 · 0 comments

Comments

@professor
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant