CamelTrail makes it easy to keep a history of attribute changes on a model
Add this line to your application's Gemfile:
gem 'camel_trail'
And then execute:
$ bundle
Or install it yourself as:
$ gem install camel_trail
- Add CamelTrail config to your initializer file.
- You need to set
current_session_user_id
to include user info incamel_trail_histories
table. - You can optionally set
table_name_prefix
to customize default table name. Defaults tocamel_trail_histories
. - CamelTrail stores backtrace info in
camel_trail_histories
. It defaults toRails.backtrace_cleaner
. You can optionally set it to your customized backtrace cleaner.
CamelTrail.config do
table_name_prefix "myapp_"
current_session_user_id { MyApp.current_session_user_id }
backtrace_cleaner { YourCustom.backtrace_cleaner }
end
class Project < ApplicationRecord
include ::CamelTrail::Recordable
end
Inlcude camel_trail
in your lib files if you need to call it there:
require "camel_trail"
Now you can access the object history through CamelTrail.for(object)
like:
project = Project.create
CamelTrail.for(project).size
# => 1
The user performing the action will be recorded from the Thread local :user_id
.
Then, require the engine in your application.rb
require "camel_trail"
Bug reports and pull requests are welcome on GitHub at https://github.com/powerhome/power-tools.
The package is available as open source under the terms of the MIT License.