Account Messages

  • travis (at appoxy)

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

    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.

    Monday Sep 28

Create your profile

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