R
R
Roman Krylov2015-04-13 20:47:24
ruby
Roman Krylov, 2015-04-13 20:47:24

Change the parameter in the link, which way would you suggest?

Help implement pagination.
There is a catalog of elements, it has a search with various parameters, all search parameters are passed in a GET request. The server processes the request and displays the elements that match the request.
There can be many elements and it is more reasonable to make pagination, in portions (pagination).
Here is an example search query:

http://localhost:4567/catalog?search[][key]=authors&search[][condition]=like&search[][value]=%D0%BF%D1%80&search[][key]=publication_date&search[][condition]=like&search[][value]=2009&search[][key]=none&search[][condition]=eql&search[][value]=&search[][key]=none&search[][condition]=eql&search[][value]=&search[][key]=none&search[][condition]=eql&search[][value]=&sort=title&limit=25&view=grid&invert=0&offset=50

The offset parameter (it is the last one in the example) specifies the offset of the starting index.
Now I need to make sure that in the pagination widget in the links to the pages there is the same address with the search parameters, but with the offset parameter changed accordingly
...&offset=0&... - the first page
...&offset=25&... - second page
...&offset=50&... - third page
etc
How to change a single parameter in the query string in Sinatra (ruby), or add it if it is not specified at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ascrazy, 2015-04-23
@xtsidx

  • Parse the url itself using URI.parse and extract the query fragment from it.
  • Parse query with Rack::Utils.parse_query
  • In the resulting hash, replace or add the necessary parameters, and build a query from it using Rack::Utils.build_query , then replace the query of the URI object obtained in the first step with a new query

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question