NoMethodError - undefined method `timestamp_sort_o

2020-04-08 12:32发布

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

3条回答
神经病院院长
2楼-- · 2020-04-08 13:06

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
查看更多
我只想做你的唯一
3楼-- · 2020-04-08 13:20

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
查看更多
我命由我不由天
4楼-- · 2020-04-08 13:21

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.

查看更多
登录 后发表回答