Skip to content

Instantly share code, notes, and snippets.

@shamil614
Created April 2, 2012 22:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamil614/2287759 to your computer and use it in GitHub Desktop.
Save shamil614/2287759 to your computer and use it in GitHub Desktop.
Paginate LinkedIn Gem Search Results
def paginate_linkedin_results(object,per_page=20)
# start = if params[:start] then params[:start] else count end
@total = object.total
@count = if object._count then object._count else per_page end
@start = if object._start then object._start else 0 end
@total_pages = (@total/per_page.to_f).ceil
url = if params[:start] then request.url else request.url + '&start=0' end
if @start <= 0
html_prev = content_tag("span", " << Prev ", :class => 'prev_page disabled')
else
html_prev = content_tag("a", " << Prev ", :class => 'prev_page', :href => url.gsub(/&start=\d*/,"&start=#{(@start) - per_page}"))
end
if (@start + per_page) >= @total
html_next = content_tag("span", " Next >> ", :class => 'next_page disabled')
else
html_next = content_tag("a", " Next >> ", :class => 'next_page', :href => url.gsub(/&start=\d*/,"&start=#{(@start) + per_page}"))
end
html_pages = ""
@total_pages.times do |x|
if @start == (x * per_page)
html_pages += content_tag("span", " #{x+1} ", :class => 'current')
else
html_pages += content_tag("a", " #{x+1} ", :href => url.gsub(/&start=\d*/,"&start=#{(x) * per_page}"))
end
end
display_count = if @total <= per_page then @total else @start + @count end
html2 = content_tag("div", html_prev + html_pages + html_next , :id => 'paginationCol2')
html1 = content_tag("div", "Displaying Contacts #{@start+1} - #{display_count} of #{@total} in total", :id => 'paginationCol1')
html = content_tag("div", html1 + html2, :id => 'pagination', :class => 'clearfix' )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment