fix global paginate helper in application helper.

This commit is contained in:
yanxd 2013-12-20 11:10:40 +08:00
parent 845937592f
commit ca16f01fd7
1 changed files with 2 additions and 6 deletions

View File

@ -622,16 +622,12 @@ class ApplicationController < ActionController::Base
## Please added code in html.
# <div class="pagination"><%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %></div>
def paginateHelper obj, pre_size=20
# current_count = pre_size * (params['page'].to_i - 1) if params['page'].to_i > 0
offset, limit = api_offset_and_limit({:limit => pre_size})
objs_all = obj
@obj_count = objs_all.count
@obj_pages = Paginator.new @obj_count, limit, params['page']
offset ||= @obj_pages.offset
if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation
obj.offset(offset).limit(limit).all
obj.limit(@obj_pages.per_page).offset(@obj_pages.offset).all
elsif obj.kind_of? Array
obj[offset..(offset+limit-1)]
obj[@obj_pages.offset, @obj_pages.per_page]
else
logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}"
nil