I am using rails 4, mongoid 4. I want to version my model with mongoid-history gem. This is my historyTracker file:
class HistoryTracker
include Mongoid::History::Tracker
end
This is initializer:
Mongoid::History.tracker_class_name = :history_tracker
This is my user model.
class User
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Paranoia
include Mongoid::Token
include SimpleEnum::Mongoid
include ActiveModel::Validations
include Mongoid::History::Trackable
field :email
field :username
track_history :on => [:username, :email],
:modifier_field => :modifier,
:modifier_field_inverse_of => :nil,
:version_field => :version,
:track_create => false,
:track_update => true,
:track_destroy => false
When I am going to seed database with rake and it give an error. I can not handle it. What is the best way to install this correctly?
I had the same issue and had to look at the source code to figure it out. Since you're using mongoid 4, there is a method in the source gem file that's called isMongoid3? We have to disable that method in our local initializer file. To do that, go to your mongoid-history.rb (in initializers) and add this:
Now when you go to your rails console and make a change, you can see the changes in your history_tracks