0.04
Low commit activity in last 3 years
There's a lot of open issues
A long-lived project that still receives updates
Mongoid Audit
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Mongoid::Audit

Gem Version Dependency Status License

MongoidAudit 1.0 is a complete rewrite and might break backwards compatibility

Since 1.0.0, mongoid_audit is no longer a fork, but a wrapper of mongoid-history, providing out-of-the-box Userstamp, RailsAdmin integration and easier setup and configuration.

Migrating from 0.x.x

  1. delete the initializer (if you had default settings).

  2. replace

include Mongoid::Audit::Trackable
track_history track_create: true, track_destroy: true

With:

include Trackable
  1. Database storage format for user / modifier in 1.0.0 was changed, since now glebtv_mongoid_userstamp gem is used to store modifier. To migrate your data you should do something like:

    HistoryTracker.all.each{|ht| ht.rename(modifier_id: :updater_id)}

  2. This gem includes storing modifier, but it is done via glebtv_mongoid_userstamp and not directly.

  3. RailsAdmin auditing adapter is still fully supported.

Installation

Add this line to your application's Gemfile:

# must be after rails_admin, if you use it
gem 'mongoid-audit', '~> 1.0.0'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mongoid-audit

Usage

Include Trackable in your models. That's it, you are done!

include Trackable

Advanced usage

Identical to Mongoid::History. See https://github.com/aq1018/mongoid-history

include Mongoid::History::Trackable
include Mongoid::Userstamp
track_history({
  track_create: true,
  track_destroy: true,
  track_update: true,
  modifier_field: :updater,
  except: ["created_at", "updated_at", "c_at", "u_at", "clicks", "impressions", "some_other_your_field"],
})

Setting modifier class name

Add to an initializer:

Mongoid::History.modifier_class_name = 'Author'
Mongoid::Userstamp.config do |c|
  c.user_reader = :current_admin
  c.user_model = :admin
end

Rails Admin Integration

Add

config.audit_with :mongoid_audit

in config/initializers/rails_admin.rb

Credits

(c) 2013-2014 http://rocketscience.pro MIT License.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request