-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
undefined method `total_count' for #<PaperTrail::Version::ActiveRecord_Relation> #2503
Comments
Hello, @minyoung. I want to solve this issue using the second method:
Can you tell me there exactly I have to use this code |
railsadminteam/rails_admin#2503 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/port/history?all=true)
Hi @vborshchov, you'd want to modify this line: https://github.com/sferik/rails_admin/blob/817e34bc6a653e3d4f0948dabeb63317be954ad8/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb#L100 and replace Your monkey patch also works. If you don't want to modify upstream library code, then going with the monkey patch might be better since it's clearer and should still work next version. We opted to go with the monkey patch until this is fixed in rails_admin itself. |
This issue can also manifest as Again, it's Those pagination options are populated in RailsAdmin::MainController#get_collection. Which is called by RailsAdmin::MainController#list_entries, and that's where it looks at the
In this case, maybe just not render the pagination controls if we're showing all? i.e. In app/views/rails_admin/main/index.html.haml
|
@minyoung @vborshchov What is your opinion on where this should be fixed? Kaminari, PaperTrail or RailsAdmin? |
I think that this should be fixed in RailsAdmin. The crux of the problem is that Kaminari selectively adds extension methods to I've created a pull request with the simplest fixes. I haven't had the time to look into adding tests (yet). |
Ah, the second exception I came across was caused by my monkey patch to work around the first exception. My bad about that. |
Fix got merged in :) |
Going to the history page (using
PaperTrail
for 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_count
defined? Kaminari::ActiveRecordRelationMethodsWhere is this module included? Kaminari::ActiveModelExtension
It seems like this module is only included when
Kaminari.config.page_method_name
on theActiveRecord::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 whenall
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 ofKaminari::ActiveRecordRelationMethods
is 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_count
is missing, then fall back tocount
? e.g.versions.try(:total_count) || versions.count
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:
The text was updated successfully, but these errors were encountered: