Closed snacks02 closed 1 year ago
The workaround that I came up with:
# all_sites_grid.rb
class AllSitesGrid < BaseGrid
scope do
[]
end
end
# sites_controller.rb
grid = AllSitesGrid.new do
Site.dataset.paginate(1, 25).to_a
end
Can you open the console and run Site.dataset.paginate(1, 25)
? If it generates an exception for you, there is nothing datagrid can do about it and you are using sequel incorrectly. You may search for support in sequel forums.
Anyway, your grid imitation code looks incorrect. It should be:
grid = AllSitesGrid.new do |scope|
scope.paginate(1, 25)
end
It works in the console:
irb(main):001:0> Site.dataset.paginate(1, 25)
=> #<Sequel::Postgres::Dataset: "SELECT * FROM \"sites\" LIMIT 25 OFFSET 0">
Not sure what you mean by grid imitation, but this is the error with your suggestion:
NoMethodError: undefined method `paginate' for Site:Class
Try the following:
# all_sites_grid.rb
class AllSitesGrid < BaseGrid
scope do
Site.dataset
end
end
# sites_controller.rb
grid = AllSitesGrid.new do |s|
s.paginate(1, 25)
end
The same error even on master
:
Sequel::Error: You cannot paginate a dataset that already has a limit
Try the following in console:
AllSitesGrid.new.scope.paginate(1,25)
AllSitesGrid.new.assets.paginate(1,25)
What is the result?
irb(main):001:0> AllSitesGrid.new.scope.paginate(1, 25)
=> #<Sequel::Postgres::Dataset: "SELECT * FROM \"sites\" LIMIT 25 OFFSET 0">
irb(main):002:0> AllSitesGrid.new.assets.paginate(1, 25)
=> #<Sequel::Postgres::Dataset: "SELECT * FROM \"sites\" LIMIT 25 OFFSET 0">
Try the following too:
AllSitesGrid.new{|s| s.paginate(1,25)}.assets.to_a
Also, let me know, which specific line is showing up in the backtrace with the error.
Sorry, but can't you try it? It should be easy to reproduce.
The test fails though.
Also, doing scope.limit(10)
results in the same error.
I have no idea how limit appears in your code. You need to provide a full controller action, view, grid and model source code.
See #312.
Thanks!
Sequel has a built-in extension for pagination that doesn't seem to work with Datagrid.