From 53465b9831daa73e2308c39f8c9db648958eff6b Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 18 Jul 2014 15:04:34 +0800 Subject: [PATCH] Pagination --- app/controllers/admin/labs_controller.rb | 2 +- app/controllers/personal_labs_controller.rb | 5 +++-- app/views/admin/labs/index.html.erb | 3 ++- lib/personal_lab/engine.rb | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/labs_controller.rb b/app/controllers/admin/labs_controller.rb index f01151f..53ff63d 100644 --- a/app/controllers/admin/labs_controller.rb +++ b/app/controllers/admin/labs_controller.rb @@ -5,7 +5,7 @@ class Admin::LabsController < OrbitMemberController before_action :get_settings,:only => [:new, :edit, :setting] def index - @labs = Lab.all + @labs = Lab.order_by(:year=>'desc').page(params[:page]).per(10) end def new diff --git a/app/controllers/personal_labs_controller.rb b/app/controllers/personal_labs_controller.rb index be3597e..c2dfc15 100644 --- a/app/controllers/personal_labs_controller.rb +++ b/app/controllers/personal_labs_controller.rb @@ -1,6 +1,6 @@ class PersonalLabsController < ApplicationController def index - labs = Lab.where(:is_hidden=>false).all + labs = Lab.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) lab_list = labs.collect do |lab| { "year" => lab.year, @@ -19,7 +19,8 @@ class PersonalLabsController < ApplicationController "th_location" => t('personal_lab.location'), "th_member" => t('users.name'), "th_detail" => t('detail') - } + }, + "total_pages" => labs.total_pages } end diff --git a/app/views/admin/labs/index.html.erb b/app/views/admin/labs/index.html.erb index 95227ec..71ebcc5 100644 --- a/app/views/admin/labs/index.html.erb +++ b/app/views/admin/labs/index.html.erb @@ -7,11 +7,12 @@ - <%= render :partial => 'lab', :collection => @labs %> + <%= render 'lab' %>
\ No newline at end of file diff --git a/lib/personal_lab/engine.rb b/lib/personal_lab/engine.rb index d6460b6..d3d237b 100644 --- a/lib/personal_lab/engine.rb +++ b/lib/personal_lab/engine.rb @@ -14,6 +14,7 @@ module PersonalLab frontend_enabled icon_class_no_sidebar "icons-user" + data_count 1..10 end end end