NoMethodError - undefined method `timestamp_sort_order' for Paper trail issue after upgrading Rails 4.2
Asked Answered
S

3

6

I used paper_trail to tracking transnational changes when I migrated rails 3.2 to rails 4.2, have got below issue:

NoMethodError - undefined method `timestamp_sort_order' for

Semitone answered 30/7, 2015 at 6:51 Comment(0)
M
8

got this on rails 6.0.0beta3 because I patched papertrail and forgot to add PaperTrail::VersionConcern, e.g.:

module PaperTrail
  class Version < ::ActiveRecord::Base
    include PaperTrail::VersionConcern
  end
end

PaperTrail::Rails::Engine.eager_load! did not fix it for me

looking at the source code it's calling it directly on an ActiveRecord::Base model, it's defined on PaperTrail::VersionConcern.

Mameluke answered 19/4, 2019 at 15:11 Comment(0)
S
4

I fixed this by adding below line in intializer paper_trail.rb file

PaperTrail::Rails::Engine.eager_load!

See my final intializers/paper_trail.rb file

PaperTrail.config.track_associations = false

PaperTrail::Rails::Engine.eager_load!

module PaperTrail

  class Version < ActiveRecord::Base
    .....
  end

end

Problem resolved....

Have updated my answer added below line extra using it with rails 5.2

PaperTrail.config.track_associations = false
Semitone answered 30/7, 2015 at 6:51 Comment(7)
hi, this solution didn't work for me. i copied the exact paper_trail.rb file I'm using ruby '2.1.2', gem 'rails', '4.0.1'Italian
Please check your paper_trail version, I used with paper_trail 4.0.0. may be you used with latest try to use paper_trail 4.0.0 hope that should work.Semitone
hi rameshwar, i was able to fix it. what I did wrong was instead of creating a paper trail initializer i created a model for it.Italian
hi rameshwar, this solution only works if I declare the module PaperTrail inside the initializer config. But if I create the module PaperTrail inside app/models/paper_trail/version, it fails.Italian
hi @rameshwar, can you help me out on this ? gist.github.com/sbpipb/502a5ff7848991f2e4c7Italian
I replied github URL, please check.Semitone
@RameshwarVyevhare This Solution is not working for me.. I am using paper_trail (10.2.1), My model in which i need paper_trail enable contains ` has_paper_trail versions: { class_name: "PimHistory" }, ignore: [:updated_at] `Sporocarp
T
0

In Rails 6, the preferred method is now to create a model, do not put model code in the initializer. This is what I'm using...

module PaperTrail
  class Version < ::ActiveRecord::Base
    include PaperTrail::VersionConcern

    belongs_to :user, foreign_key: :whodunnit
  end
end
Tetrafluoroethylene answered 10/1, 2020 at 20:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.