Module: Headmin::Pagination

Included in:
MediaController
Defined in:
app/controllers/concerns/headmin/pagination.rb

Instance Method Summary collapse

Instance Method Details

#pageObject



12
13
14
15
16
17
18
19
20
# File 'app/controllers/concerns/headmin/pagination.rb', line 12

def page
  if params[:page]
    params[:page]
  elsif params[:start]
    (params[:start].to_i / per_page) + 1
  else
    1
  end
end

#paginate(collection) ⇒ Object



3
4
5
6
7
8
9
10
# File 'app/controllers/concerns/headmin/pagination.rb', line 3

def paginate(collection)
  @records_filtered = collection.count
  if collection.is_a?(Array)
    Kaminari.paginate_array(collection).page(page).per(per_page)
  else
    collection.page(page).per(per_page)
  end
end

#per_pageObject



22
23
24
25
# File 'app/controllers/concerns/headmin/pagination.rb', line 22

def per_page
  length = params[:per_page].to_i
  (length > 0) ? length : 24
end