2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/baza_models/helpers/ransacker_helper.rb', line 2
def bm_paginate_content(collection)
require "html_gen"
new_params = params.dup.permit!
current_page = collection.page
total_pages = collection.total_pages
container = HtmlGen::Element.new(:div)
if current_page > 1
new_params[:page] = current_page - 1
container.add_ele(:a, str: "Previous", attr: {href: url_for(new_params)})
else
container.add_ele(:span, str: "Previous")
end
1.upto(collection.total_pages) do |page_i|
new_params[:page] = page_i
link = container.add_ele(:a, attr: {href: url_for(new_params)})
if page_i == current_page
link.add_ele(:b, str: page_i.to_s)
else
link.add_str(page_i.to_s)
end
end
if current_page < total_pages
new_params[:page] = current_page + 1
container.add_ele(:a, str: "Next", attr: {href: url_for(new_params)})
else
container.add_ele(:span, str: "Next")
end
container.html
end
|