travis (at appoxy)

Should we add paginate method so will_paginate will work out of the box?

Posted by travis (at appoxy) on September 28th 2009 11:59 PM

Currently to get will_paginate to work you have to:

1: Add this somewhere in your code (eg: environment.rb):

SimpleRecord::ResultsArray.class_eval do
  def paginate(options = {})
    raise ArgumentError, "parameter hash expected (got #{options.inspect})" unless Hash === options

    WillPaginate::Collection.create(
        options[:page] || 1,
        options[:per_page] || 30,
        options[:total_entries] || self.length
    ) { |pager|
      pager.replace self[pager.offset, pager.per_page].to_a
    }
  end
end

2: Find then paginate when querying, for eg:

@posts = Post.find(:all, :order => 'created_at DESC').paginate(:page => params[:page], :per_page => 25)

Step 1 and 2 could all be condensed to behave like the simplest use of will_paginate:

@posts = Post.paginate :page => params[:page], :order => 'created_at DESC'

Might make sense to include this in SimpleRecord to ease the transition.

You must be a project member to post a new comment.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

A drop in replacement for ActiveRecord for Amazon SimpleDB.

Code hosted at http://github.com/appoxy/simple_record

Shared Ticket Bins

People watching this message