Skip to content

undefined method `total_count' for #<PaperTrail::Version::ActiveRecord_Relation> #2503

@minyoung

Description

@minyoung

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions