Skip to content

Instantly share code, notes, and snippets.

@dharamgollapudi
Forked from maxivak/audit_globalize.md
Created October 20, 2019 16:54
Show Gist options
  • Save dharamgollapudi/fe532768a054cdb5f725911eac3ad883 to your computer and use it in GitHub Desktop.
Save dharamgollapudi/fe532768a054cdb5f725911eac3ad883 to your computer and use it in GitHub Desktop.
Rails: Audit Globalize translations
  • 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.

Audited and Globalize

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

Install audited

Gemfile

gem "audited"
  • install db tables
rails generate audited:install
rake db:migrate

Globalize

Gemfile

gem 'globalize', '~> 5.0.0'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment