paper_trail: Custom initializer breaks PaperTrail 3.0.3 (rails 3.2)

3.0.3 seems to be breaking when calling has_paper_trail in a model. 3.0.2 works fine. top of the stack:

undefined method `timestamp_sort_order' for #<Class:0x007fd1d02fad60>
activerecord (3.2.18) lib/active_record/dynamic_matchers.rb:55:in `method_missing'
paper_trail (3.0.3) lib/paper_trail/has_paper_trail.rb:70:in `has_paper_trail'

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 16 (1 by maintainers)

Commits related to this issue

Most upvoted comments

So one workaround that you can use for now is placing this line in your custom initializer, like so:

# config/initializers/paper_trail.rb
module PaperTrail
  class Version < ActiveRecord::Base
    include PaperTrail::VersionConcern
  end
end

But, it seems as though then the model doesn’t end up getting loaded in through the Rails::Engine, which defeats the whole purpose of the feature, so I need to do more research to figure out what we can do to work around that.

Another workaround is to manually require the version class from your initializer. Again, I believe this circumvents the benefits that come from loading the model in through a Rails::Engine to begin with, but it is another way to do it:

# config/initializers/paper_trail.rb
require 'paper_trail/frameworks/active_record/models/paper_trail/version'

module PaperTrail
  class Version < ActiveRecord::Base
  end
end

After doing a little more experimentation, it appears as though this may be the correct way to make it work properly. You want to change your initializer so that the model has already been eager loaded by the engine by the time this code gets executed, by calling eager_load! on the engine, like so:

# config/initializers /paper_trail.rb
PaperTrail::Rails::Engine.eager_load!

module PaperTrail
  class Version < ActiveRecord::Base
    # custom code goes here
  end
end

Looks like I will need to update the README accordingly. Glad I was able to find the proper method for getting this to work. I’ll keep this open until I can update the README appropriately.