#51 will_paginate

In edge rails (soon to be Rails 2.0), the built-in pagination has been moved into a plugin: classic_pagination. I recommend jumping over to the will_paginate plugin as shown in this episode.
# models/product.rb
def self.search(search, page)
  paginate :per_page => 5, :page => page,
           :conditions => ['name like ?', "%#{search}%"],
           :order => 'name'
end

# products_controller.rb
def index
  @products = Product.search(params[:search], params[:page])
end<!-- products/index.rhtml -->
<%= will_paginate @products %>

你可能感兴趣的:(Rails)