Comments (8)
That is very interesting. Thank you for looking into that!
The bare-bone Rails seems to be working as expected, which implies that the deep_merge
method is overriden by something else.
{ "page" => 5 }.deep_merge("page" => 7)
# => {"page"=>7}
Would you mind checking the source location for the deep_merge
method you are running locally?
deep_merge_method = @params.method(:deep_merge)
loop do
pp deep_merge_method.source_location
deep_merge_method = deep_merge_method.super_method
break if deep_merge_method.nil?
end
from kaminari.
@yuki24 it sounds like the problem is fully solved, thank you so much for your help. the deep_merge gem was indeed declared below the rails gem. I will go ahead and close this issue now
from kaminari.
that does not mean we do not have to understand the root cause
Absolutely :)
I did try creating a fresh app following your example and everything worked as expected. So I think it could be a conflict with another gem, like you said. I did try removing the only gem I suspected could be causing the issues, but that did not fix the problem. The data-remote was added by me (sorry forgot to mention it in the example -- removing it does not help).
I can investigate some more tomorrow, but for now I think it might be helpful to share my findings
7f08863 seems to be the commit that fixes the problem we are facing. I checked by checking out a bunch of commit refs in my local clone of the gem until I found one that worked
Adding some pp logs to see whats going on with the old code for params_for
reveals the deep_merge does not work as expected for us with ?page=5
:
def params_for(page)
pp "LOGGING HERE"
page_params = Rack::Utils.parse_nested_query("#{@param_name}=#{page}")
pp page_params
page_params = @params.deep_merge(page_params)
pp page_params
21:54:17 web.1 | {"page"=>"4"}
21:54:17 web.1 | {"page"=>"5", "controller"=>"courses", "action"=>"index"}
21:54:17 web.1 | "LOGGING HERE"
21:54:17 web.1 | {"page"=>"5"}
21:54:17 web.1 | {"page"=>"5", "controller"=>"courses", "action"=>"index"}
21:54:17 web.1 | "LOGGING HERE"
21:54:17 web.1 | {"page"=>"6"}
21:54:17 web.1 | {"page"=>"5", "controller"=>"courses", "action"=>"index"}
21:54:17 web.1 | "LOGGING HERE"
21:54:17 web.1 | {"page"=>"7"}
21:54:17 web.1 | {"page"=>"5", "controller"=>"courses", "action"=>"index"}
from kaminari.
Good catch! That helps a lot
In the bare-bones Rails app, I only have 1 source_location (learned something new today):
["/Users/mroudnitski/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/activesupport-7.1.3/lib/active_support/deep_mergeable.rb", 29]
In my real app, I have 2:
22:14:52 web.1 | ["/Users/mroudnitski/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/deep_merge-1.2.2/lib/deep_merge/deep_merge_hash.rb",
22:14:52 web.1 | 18]
22:14:52 web.1 | ["/Users/mroudnitski/.asdf/installs/ruby/3.2.3/lib/ruby/gems/3.2.0/gems/activesupport-7.1.3/lib/active_support/deep_mergeable.rb",
22:14:52 web.1 | 29]
Looks like its coming from a gem called deep_merge which my app depends on because of the config gem
I'm not too sure yet why upgrading to Rails 7.1 surfaced this problem, but I tried upgrading the config gem from 2.2 (old pin) to the latest (5.x) and it looks like Kaminari 1.2.2 is working so far :)
from kaminari.
Perhaps it is related to this commit rails/rails@43b9803 on Rails, where the method definition has been moved to its own module. Direct method definitions take the precedence over module-defined methods, so Rails' deep_merge
was picked up in v7.0 and older.
Now with Rails 7.1, things could be a bit unpredictable as it now depends on the order of the modules that get included by the Hash
class. Looking at the pp
output, it was probably the case that gem "deep_merge"
was declared below gem "rails"
.
from kaminari.
Thanks for reporting. I am also using Kaminari 1.22 and Rails 7.1.3 on https://toprubycompanies.info/consultancies and pagination works as expected. Could you provide an example that reproduces your issue?
from kaminari.
Hi @yuki24, we were able to replicate the problem with the most basic example from the README and all our extra filtering/sorting removed. In our case, this looked like:
# courses_controller.rb
def index
@courses = Course.page(params[:page])
end
# index.html.erb
<% @courses.each do |course| %>
<%= course.name %>
<% end %>
<%= paginate @courses %> <%# *not* using custom views in views/kaminari/*.html.erb, just using the standard paginate views from the gem %>
Unfortunately I can't provide the full repository/source code as its internal, but I am happy to provide more information where I can. We are using Ruby 3.2.3 and Turbo 8 in case that helps more.
Like I said we do not see this problem in the current master branch of this gem. Any reason not to release a new version of this gem to rubygems.org?
Thanks for your time, I've also attached an example of what we see with the basic code from above (just on the Article model instead of Course)
Screen.Recording.2024-02-20.at.5.45.08.PM.mov
from kaminari.
Like I said we do not see this problem in the current master branch of this gem. Any reason not to release a new version of this gem to rubygems.org?
We can totally do that, but that does not mean we do not have to understand the root cause.
I have created an example app with Ruby 3.2.3m Rails 7.1.3 and Kaminari 1.2.2, and I still can't replicate the issue.
$ ruby -v
ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [arm64-darwin23]
$ rails -v
Rails 7.1.3
$ rails new kaminari-1119
$ cd kaminari-1119
$ bundle add kaminari
$ rails g scaffold users name:string
$ rake db:migrate
$ rails runner '200.times { User.create!(name: "User #{_1}") }'
$ perl -i -pe 's/all/page\(params[:page]\)/' app/controllers/users_controller.rb
$ echo "<%= paginate @users %>" >> app/views/users/index.html.erb
$ rails s
And each one of the links has a page
parameter as expected:
I see that you have a data-remote
attribute in your a
tags. Do you happen to have custom Kaminari templates or have a gem installed that potentially ships with custom ones?
from kaminari.
Related Issues (20)
- undefined local variable or method `paginator' for _page.html.erb:22 partial HOT 2
- Undefined method `without_count' HOT 2
- Update wiki link in GitHub "About" section HOT 1
- issue on method_missing due to separation of positional and keyword arguments in Ruby 3
- Is it possible to add 'data-turbo-action' to the paginate helper? HOT 4
- How to use "Creating Friendly URLs and Caching" in "member do" ?
- With the update from i18n to v1.11.0 `:zero` in not longer supported as key
- Problem Monkey Patching Rails 7.0
- render error for js.erb
- when large table query, use total_count and total_pages slow
- paginate view helper is failing with includes HOT 3
- Updating content_for blocks
- `link_to_first_page` / `link_to_last_page` ?
- inconsistent results in case of LEFT OUTER JOIN, GROUP BY and HAVING HOT 2
- Array doesn't get paginated when total count is passed in HOT 1
- Ambiguous column "id" when PG COUNT is used with certain joins HOT 1
- using symbol as param_name gives an error in params_for
- Wish to report a security vulnerability HOT 2
- Paginator stops working correctly when I Upgraded site to Ruby 3.3.1 & Rails 7.1. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kaminari.