- Globalize adds model translations to ActiveRecord models.
- Audited is an ORM extension that logs all changes to your models.
Using Audited gem it will only logs changes to the base model and ignore changes to the translation table.
Below is how to add audited to the translation model.
Globalize adds nested class Translation inside your model class.
We will reopen Translation class inside my model to add 'audited':
class Mymodel < ApplicationRecord
# translation
translates :title, :description
# audit
audited
# ADD THIS
Translation.class_eval do
audited
end
Gemfile
gem "audited"
- install db tables
rails generate audited:install
rake db:migrate
Gemfile
gem 'globalize', '~> 5.0.0'
- See https://github.com/globalize/globalize to install globalize.
Instead of adding inside multiple models wherever we are using translate. How we can use concerns and include that concern inside the model to avoid code duplication?