From 8e5ab6e13e064c3f8b88aef6ad5aad256b766b4c Mon Sep 17 00:00:00 2001 From: manson Date: Fri, 18 Jul 2014 15:02:35 +0800 Subject: [PATCH] Pagination --- app/controllers/admin/experiences_controller.rb | 2 +- app/controllers/personal_experiences_controller.rb | 5 +++-- app/views/admin/experiences/index.html.erb | 3 ++- lib/personal_experience/engine.rb | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/experiences_controller.rb b/app/controllers/admin/experiences_controller.rb index 10eb579..1c70e29 100644 --- a/app/controllers/admin/experiences_controller.rb +++ b/app/controllers/admin/experiences_controller.rb @@ -5,7 +5,7 @@ class Admin::ExperiencesController < OrbitMemberController before_action :get_settings,:only => [:new, :edit, :setting] def index - @experiences = Experience.all + @experiences = Experience.order_by(:end_date=>'desc',:start_date=>'desc').page(params[:page]).per(10) end def new diff --git a/app/controllers/personal_experiences_controller.rb b/app/controllers/personal_experiences_controller.rb index ec9fcfb..272f154 100644 --- a/app/controllers/personal_experiences_controller.rb +++ b/app/controllers/personal_experiences_controller.rb @@ -1,6 +1,6 @@ class PersonalExperiencesController < ApplicationController def index - experiences = Experience.where(:is_hidden=>false).all + experiences = Experience.where(:is_hidden=>false).order_by(:end_date=>'desc',:start_date=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) experience_list = experiences.collect do |experience| { "member" => experience.member_profile.name, @@ -21,7 +21,8 @@ class PersonalExperiencesController < ApplicationController "th_department" => t('personal_experience.department'), "th_job_title" => t('personal_experience.job_title'), "th_detail" => t('detail') - } + }, + "total_pages" => experiences.total_pages } end diff --git a/app/views/admin/experiences/index.html.erb b/app/views/admin/experiences/index.html.erb index c8179a8..446fd37 100644 --- a/app/views/admin/experiences/index.html.erb +++ b/app/views/admin/experiences/index.html.erb @@ -8,7 +8,7 @@ - <%= render :partial => 'experience', :collection => @experiences %> + <%= render 'experience' %> @@ -17,5 +17,6 @@ <%= link_to content_tag(:i, nil, :class => 'icon-cog icon-white') + t('setting'), admin_experience_setting_path, :class => 'btn btn-primary pull-right' %> \ No newline at end of file diff --git a/lib/personal_experience/engine.rb b/lib/personal_experience/engine.rb index ba12643..8f627ec 100644 --- a/lib/personal_experience/engine.rb +++ b/lib/personal_experience/engine.rb @@ -13,6 +13,7 @@ module PersonalExperience frontend_enabled icon_class_no_sidebar "icons-user" + data_count 1..10 end end end