Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

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

travis (at appoxy)

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.

Posted by travis (at appoxy) · September 28th, 2009 @ 11:59 PM

0 replies

No replies yet.

You must be logged in as a project member to reply.