you are here: codestackercodes [RSS] → tag will_paginate [RSS]

translating will paginate

# paste in your environment.rb


WillPaginate::ViewHelpers.pagination_options[:prev_label]=I18n.t("pagination.prev")
WillPaginate::ViewHelpers.pagination_options[:next_label]=I18n.t("pagination.next")

# and create the respective translation in your translation file

#    pagination:

#      next: "próximo" 

#      prev: "anterior" 

record count and current records using will_paginate

returns Displaying records 1 - 10 of 35. used in codestacker

# 1) model:


  def self.per_page
    10
  end

# 2) helper:


  def paginate_range(in_collection, in_tot_count)
    endnumber = in_collection.offset + in_collection.per_page > in_tot_count ? 
      in_tot_count : in_collection.offset + in_collection.per_page
    "Displaying records #{in_collection.offset + 1} - #{endnumber} of #{in_tot_count}"
  end

# 3) controller 


    @codes = Code.paginate :conditions => conditions, :page => params[:page]
    @codes_count = Code.count

# 4) view: 


<%= paginate_range @codes, @codes_count %>
Displaying all 2 Code