From 0a087e1df47cacdd28689940c9c875446d554123 Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 18 Jul 2014 15:05:27 +0800 Subject: [PATCH] Pagination --- app/controllers/admin/patents_controller.rb | 2 +- app/controllers/personal_patents_controller.rb | 5 +++-- app/views/admin/patents/index.html.erb | 3 ++- lib/personal_patent/engine.rb | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/patents_controller.rb b/app/controllers/admin/patents_controller.rb index 9670885..aacb9ba 100644 --- a/app/controllers/admin/patents_controller.rb +++ b/app/controllers/admin/patents_controller.rb @@ -5,7 +5,7 @@ class Admin::PatentsController < OrbitMemberController before_action :get_settings,:only => [:new, :edit, :setting] def index - @patents = Patent.all + @patents = Patent.order_by(:year=>'desc').page(params[:page]).per(10) end def new diff --git a/app/controllers/personal_patents_controller.rb b/app/controllers/personal_patents_controller.rb index 662f6a8..26a0f2a 100644 --- a/app/controllers/personal_patents_controller.rb +++ b/app/controllers/personal_patents_controller.rb @@ -1,6 +1,6 @@ class PersonalPatentsController < ApplicationController def index - patents = Patent.where(:is_hidden=>false).all + patents = Patent.where(:is_hidden=>false).order_by(:year=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) patent_list = patents.collect do |patent| { "publication_date" => patent.publish_date, @@ -20,7 +20,8 @@ class PersonalPatentsController < ApplicationController "th_patent_no" => t('personal_patent.patent_no'), "th_patent_country" => t("personal_patent.patent_country"), "th_authors" => t('users.name') - } + }, + "total_pages" => patents.total_pages } end diff --git a/app/views/admin/patents/index.html.erb b/app/views/admin/patents/index.html.erb index 3c41822..3f517e6 100644 --- a/app/views/admin/patents/index.html.erb +++ b/app/views/admin/patents/index.html.erb @@ -9,7 +9,7 @@ - <%= render :partial => 'patent', :collection => @patents %> + <%= render 'patent' %> @@ -18,5 +18,6 @@ <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t('setting'), admin_patent_setting_path, :class => 'btn btn-primary pull-right' %> \ No newline at end of file diff --git a/lib/personal_patent/engine.rb b/lib/personal_patent/engine.rb index c115434..12d2e5a 100644 --- a/lib/personal_patent/engine.rb +++ b/lib/personal_patent/engine.rb @@ -14,6 +14,7 @@ module PersonalPatent frontend_enabled icon_class_no_sidebar "icons-user" + data_count 1..10 end end end