Going to the history page (using PaperTrail for the auditing) and showing all history throws an error:
undefined method `total_count' for #PaperTrail::Version::ActiveRecord_Relation
(example url: http://localhost:3000/admin/model/history?all=true)
From what I can tell, this seems to only affect when showing all history. What I've dug up so far:
Where is this missing total_count defined? Kaminari::ActiveRecordRelationMethods
Where is this module included? Kaminari::ActiveModelExtension
It seems like this module is only included when Kaminari.config.page_method_name on the ActiveRecord::Model is called though?
Well, when is Kaminari.config.page_method_name called? RailsAdmin::Extensions::PaperTrail::AuditingAdapter.listing_for_model_or_object (which corresponds to the stack trace)
And it seems like Kaminari.config.page_method_name is only called when all is falsey.
So, if I'm understanding this correctly, then when all is truthy, Kaminari.config.page_method_name is not called, which means that the inclusion of Kaminari::ActiveRecordRelationMethods is not triggered, hence the missing method total_count.
What now? A couple ideas (in no particular order) comes to mind
- just call
Kaminari.config.page_method_name? But then the default limit (25) takes place. So then use a high limit? e.g. versions.page.limit(100000)
- if
total_count is missing, then fall back to count? e.g. versions.try(:total_count) || versions.count
- remove
Show all and instead make the items per page configurable?
I've tested the first 2 ideas, and both of them work.
Thoughts? Opinions? Other suggestions?
Top few lines of the stack trace:
activerecord (4.2.0) lib/active_record/relation/delegation.rb:136:in `method_missing'
activerecord (4.2.0) lib/active_record/relation/delegation.rb:99:in `method_missing'
rails_admin (0.8.1) lib/rails_admin/extensions/paper_trail/auditing_adapter.rb:101:in `listing_for_model_or_object'
rails_admin (0.8.1) lib/rails_admin/extensions/paper_trail/auditing_adapter.rb:74:in `listing_for_model'
rails_admin_history_rollback (0.0.3) lib/rails_admin_history_rollback/config/actions/history_index.rb:26:in `block (2 levels) in <class:HistoryIndex>'
rails_admin (0.8.1) app/controllers/rails_admin/main_controller.rb:22:in `instance_eval'
rails_admin (0.8.1) app/controllers/rails_admin/main_controller.rb:22:in `history_index'
Going to the history page (using
PaperTrailfor the auditing) and showing all history throws an error:(example url: http://localhost:3000/admin/model/history?all=true)
From what I can tell, this seems to only affect when showing all history. What I've dug up so far:
Where is this missing
total_countdefined? Kaminari::ActiveRecordRelationMethodsWhere is this module included? Kaminari::ActiveModelExtension
It seems like this module is only included when
Kaminari.config.page_method_nameon theActiveRecord::Modelis called though?Well, when is
Kaminari.config.page_method_namecalled? RailsAdmin::Extensions::PaperTrail::AuditingAdapter.listing_for_model_or_object (which corresponds to the stack trace)And it seems like
Kaminari.config.page_method_nameis only called whenallis falsey.So, if I'm understanding this correctly, then when
allis truthy,Kaminari.config.page_method_nameis not called, which means that the inclusion ofKaminari::ActiveRecordRelationMethodsis not triggered, hence the missing methodtotal_count.What now? A couple ideas (in no particular order) comes to mind
Kaminari.config.page_method_name? But then the default limit (25) takes place. So then use a high limit? e.g.versions.page.limit(100000)total_countis missing, then fall back tocount? e.g.versions.try(:total_count) || versions.countShow alland instead make the items per page configurable?I've tested the first 2 ideas, and both of them work.
Thoughts? Opinions? Other suggestions?
Top few lines of the stack trace: