Skip to content

custom_audits_class_per_model #753

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ By default changes are stored in YAML format. If you're using PostgreSQL, then y

If you're using something other than integer primary keys (e.g. UUID) for your User model, then you can use `rails generate audited:install --audited-user-id-column-type uuid` to customize the `audits` table `user_id` column type.

If you would like to use a custom audits table, you can use `rails generate audited:install --audited-table-name custom_audits` to specify a custom audit table name, it will generate a schema migration file and a custom audit model in `app/models`.

#### Upgrading

If you're already using Audited (or acts_as_audited), your `audits` table may require additional columns. After every upgrade, please run:
Expand Down Expand Up @@ -416,7 +418,9 @@ class CustomAudit < Audited::Audit
end
end
```

Then set it in an initializer:

```ruby
# config/initializers/audited.rb

Expand All @@ -425,6 +429,31 @@ Audited.config do |config|
end
```

You can also specify a custom audit class on a per-model basis, which will override default audit class for the exact model.

```ruby
class User < ActiveRecord::Base
audited as: "CustomAudit"
end

# or with a custom class
class User < ActiveRecord::Base
audited as: CustomAudit
end
```

You can also supply a custom table name for the audit records.

```ruby
class CustomAudit < Audited::Audit
self.table_name = "custom_audits"
end

class User < ActiveRecord::Base
audited as: CustomAudit
end
```

### Enum Storage

In 4.10, the default behavior for enums changed from storing the value synthesized by Rails to the value stored in the DB. You can restore the previous behavior by setting the store_synthesized_enums configuration value:
Expand Down
Loading