I am fetching some rows from the database in my controller with this query :
@main = connection.execute("select code_ver, result from mastertest;")
Now in my html.erb, I am displaying the results in a table like this:
<% @level1.each do |row1| %>
<table id="tbl_main1" name="tbl_main1">
<tr bgcolor="#D1D1D1">
<td width="60%" <%= row1[0] %>></td>
<td width="20%"><%= row1[2] %></td>
<td width="20%"><%= row1[1] %></td>
</tr>
</table>
I am fetching a lot of rows here. But I want to show only say 15 results at once, and have some kind of buttons ‘next’ and ‘previous’ which would cycle through the results. How would I do that ?
I’d suggest creating an Active Record model to represent your mastertest database table. Then, with the help of the
will_paginategem, you could do the following in your controller:And then in your view:
The
will_paginateview helper will generate pagination links like [prev] [1] [2] [3] [next]. Take a look at the will_paginate gem on github for more options.