README.md in audited-4.3.0 vs README.md in audited-4.4.0

- old
+ new

@@ -1,21 +1,22 @@ Audited [![Build Status](https://secure.travis-ci.org/collectiveidea/audited.svg)](http://travis-ci.org/collectiveidea/audited) [![Dependency Status](https://gemnasium.com/collectiveidea/audited.svg)](https://gemnasium.com/collectiveidea/audited)[![Code Climate](https://codeclimate.com/github/collectiveidea/audited.svg)](https://codeclimate.com/github/collectiveidea/audited) [![Security](https://hakiri.io/github/collectiveidea/audited/master.svg)](https://hakiri.io/github/collectiveidea/audited/master) ======= **Audited** (previously acts_as_audited) is an ORM extension that logs all changes to your models. Audited can also record who made those changes, save comments and associate models related to the changes. -Audited currently (4.x) works with Rails 5.0 and 4.2. It may work with 4.1 and 4.0, but this is not guaranteed. +Audited currently (4.x) works with Rails 5.1, 5.0 and 4.2. It may work with 4.1 and 4.0, but this is not guaranteed. For Rails 3, use gem version 3.0 or see the [3.0-stable branch](https://github.com/collectiveidea/audited/tree/3.0-stable). ## Supported Rubies Audited supports and is [tested against](http://travis-ci.org/collectiveidea/audited) the following Ruby versions: * 2.1.5 * 2.2.4 * 2.3.1 +* 2.4.1 Audited may work just fine with a Ruby version not listed above, but we can't guarantee that it will. If you'd like to maintain a Ruby that isn't listed, please let us know with a [pull request](https://github.com/collectiveidea/audited/pulls). ## Supported ORMs @@ -24,25 +25,22 @@ ## Installation Add the gem to your Gemfile: ```ruby -gem "audited", "~> 4.3" +gem "audited", "~> 4.4" ``` -If you are using rails 5.0, you would also need the following line in your Gemfile. -```ruby -gem "rails-observers", github: 'rails/rails-observers' -``` - Then, from your Rails app directory, create the `audits` table: ```bash $ rails generate audited:install $ rake db:migrate ``` +If you're using PostgreSQL, then you can use `rails generate audited:install --audited-changes-column-type jsonb` (or `json`) to store audit changes natively with its JSON column types. + #### Upgrading If you're already using Audited (or acts_as_audited), your `audits` table may require additional columns. After every upgrade, please run: ```bash @@ -164,11 +162,11 @@ ``` Outside of a request, Audited can still record the user with the `as_user` method: ```ruby -Audited::Audit.as_user(User.find(1)) do +Audited.audit_class.as_user(User.find(1)) do post.update_attribute!(title: "Hello, world!") end post.audits.last.user # => #<User id: 1> ``` @@ -215,11 +213,11 @@ has_many :users has_associated_audits end ``` -Now, when a audit is created for a user, that user's company is also saved alongside the audit. This makes it much easier (and faster) to access audits indirectly related to a company. +Now, when an audit is created for a user, that user's company is also saved alongside the audit. This makes it much easier (and faster) to access audits indirectly related to a company. ```ruby company = Company.create!(name: "Collective Idea") user = company.users.create!(name: "Steve") user.update_attribute!(name: "Steve Richert") @@ -254,9 +252,29 @@ To disable auditing on an entire model: ```ruby User.auditing_enabled = false +``` + +### Custom `Audit` model + +If you want to extend or modify the audit model, create a new class that +inherits from `Audited::Audit`: +```ruby +class CustomAudit < Audited::Audit + def some_custom_behavior + "Hiya!" + end +end +``` +Then set it in an initializer: +```ruby +# config/initializers/audited.rb + +Audited.config do |config| + config.audit_class = CustomAudit +end ``` ## Gotchas ### Using attr_protected with Rails 4.x