Skip to content

Instantly share code, notes, and snippets.

@maxivak
Last active January 26, 2025 08:27
Show Gist options
  • Save maxivak/e1c6b39b9ec5a16d2d3daacbdd2a64d4 to your computer and use it in GitHub Desktop.
Save maxivak/e1c6b39b9ec5a16d2d3daacbdd2a64d4 to your computer and use it in GitHub Desktop.

Revisions

  1. maxivak revised this gist Dec 19, 2017. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion audit_globalize.md
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,9 @@ Below is how to add audited to the translation model.

    # Audited and Globalize

    Reope translation class inside my model:
    Globalize adds nested class Translation inside your model class.

    We will reopen Translation class inside my model to add 'audited':

    ```
    class Mymodel < ApplicationRecord
  2. maxivak created this gist Dec 19, 2017.
    54 changes: 54 additions & 0 deletions audit_globalize.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    * [Globalize](https://github.com/globalize/globalize) adds model translations to ActiveRecord models.
    * [Audited](https://github.com/collectiveidea/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

    Reope translation class inside my model:

    ```
    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'
    ```


    * See https://github.com/globalize/globalize to install globalize.