Closed gwynolanga closed 2 years ago
@cuurjol
I think a lot of the complexity can be avoided, by taking a different approach. If you will permit me, consider using turbo-frames. Some rough ideas - there may be mistakes in them, but I hope you can see the general idea.
def show
@check = Repository::Check.find(params[:id])
@pagy, @offenses_files = pagy(@check.offenses_files)
authorize(@check)
end
<% @offenses_files.each do |offence_file|%>
<% turbo_frame_tag offence_file, src: offence_file_offences_path(@offence_file) do %>
<% end %>
<% end %>
# OffencesController
def index
@offence_file = OffenceFile.find(params[:id])
@pagy, @offenses = pagy(@offence.offence_files)
# authorize(@offence.check)
end
And that's it! No complex logic on the back end. Yes, there are extra requests. If you want to avoid that, then simply eager load the records and use the same partials.
Any further questions, please feel free to ask.
For cuurjol/askme/config/application.rb file path example (third nested table): Expected result: rule pagination flip a next page (second) without side effects for others. Actual result: all existing rule paginations (nested tables) flip a next page (second).
You are using the same page param for all your different/independent paginations in the same request. How can they know that you mean to paginate each of them independently?
https://ddnexus.github.io/pagy/how-to#customize-the-page-param https://www.imaginarycloud.com/blog/how-to-paginate-ruby-on-rails-apps-with-pagy/ (a bit outdated but the concept is the same)
Closing this because it is not an issue. Please use the indicated channel to ask questions.
Hello! I have a problem with a main pagination with others nested pagination by nested collections for JSON or Hash structure. I have
Check
ActiveRecrod model which containsoffenses_files
attribute (json type):The structure above is not ActiveRecord, it is just a Hash for Ruby. I want to paginate it simultaneously by file pathes (
file_path
Hash key) and by rules (rule
Hash key), i.e to create a complicated pagination.I did it for my application like this:
The picture above has a pagination for the file pathes (main table) and have nested paginations by rule for each file path (nested tables). Below is the following controller code snippet:
Below is the following view code snippet:
The controller code snippet looks like OK, but when I try to flip a next page for any rule paginations (nested tables) I capture the following exception:
After a lot of research in debug mode, I noticed that each pagination for rules (nested tables) create a request with the following query parameters:
file=5&offense=2
wherefile=5
is the fifth page for file pathes (main table) andoffense=2
- is the second page for rules (nested tables) and an exception will be raised for those rules (nested tables) which should not have a pagination. I fixed the exception by the following controller code:The updated controller code snippet looks like OK, but when I try to flip a next page for one rule paginations (nested tables) I noticed that other rule paginations (nested tables) also flip a next page:
Final request for the picture above looks the following: http://localhost:3000/repositories/4/checks/3?file=5&offense=2
For
cuurjol/askme/config/application.rb
file path example (third nested table): Expected result: rule pagination flip a next page (second) without side effects for others. Actual result: all existing rule paginations (nested tables) flip a next page (second).Is there any way to solve my problem? Perhaps, I need to add
id
Hash keys for each file path and rule, but I don't know how to build a request with it as additional parameter for Pagy gem.