I’m using Sinatra and Ruby 1.9.3.
I have a list of items and want to paginate them. I’m new to web development so I don’t know how to do that in detail.
I don’t know how to implement the links for each page, such as the link to page2 on page1. Should I do it like so:
<a href='?page=2'
I don’t think that’s a good idea because it would overwrite my other parameters like ?searchterm= and ?sort=? and it wouldn’t take the existing ?page= parameters into account.
My idea was to use the same form as my searchterm etc., and change the value via buttons and JavaScript. But, that seems to be quite complicated and all big websites, including stackoverflow.com, use links for their pagination.
How do I achieve pagination which features the following:
- Include other parameters when going to another page.
- Overwrite the existing
?page=parameter. - No Javascript (optional, but would be good).
You can always load the necessary parameters into instance vars:
and then use it as you were doing: