Giter Club home page Giter Club logo

paginating_find's Introduction

THIS PLUGIN IS DEPRECATED.

Visit http://cardboardrocket.com/pages/paginating_find for more documentation.

This plugin makes it easy to page through your model instances by enhancing the default ActiveRecord::Base#find method.  In general, you can expect pagination to work with the standard #find options, including :conditions, :group, :order, :limit, and :include.  To activate paging, just specify the :page option.  You may also provide additional paging options that will control the behavior of the enumerator returned by the #find method.  The following options are supported:

:size    => Number of records in each page of results. Defaults to the total
            record count or 10, whichever is smaller.
:current => The current page. Optional, defaults to the first page: 1.
:first   => The first page. Optional, defaults to the current page.
:auto    => Automatically load the next page during invocation of #each. Defaults to false.
:count   => Number of records used to determine #page_count. Specifying this
            option prevents the plugin from running a count query, which may 
            be helpful if the table to be queried is very large.

Note: if :page is specified, then the :offset option is not supported and an Exception to that effect will be raised.

Some handy methods you can call on the result returned by #find, when paging is enabled:

#each               => Iterate over the results
#size               => Number of records on all pages combined (total size)
#page_size          => Number of records on each page
#page_count         => Number of pages
#empty?             => Are there any results?
#to_a               => Create an array of the records on the current page, or all pages if :auto => true
#move!(num)         => Move to a specific page number
#page_exists?(num)  => Does this page number exist?
#first_page!        => Move to the first page
#first_page         => Page number of the first page
#last_page!         => Move to the last page
#last_page          => Page number of the last page
#next_page?         => Is there another page available?
#next_page!         => Move to the next page, if one exists
#next_page          => Page number of the next page
#previous_page?     => Does a previous page exist?
#previous_page!     => Move to the previous page, if one exists
#previous_page      => Page number of the previous pages
#first_item         => The index of the first item on the page
#last_item          => The index of the last item on the page
#load_page          => Reload the current page



- Simple Example -------------------------------------------------------

# Get the first page of 'new' Cogs. Each page contains
# 10 cogs, and no more than 100 cogs will be returned.
cogs = Cog.find(:all, 
                :page,
                :conditions => ["category = 'new'"],
                :limit => 100)

# Print the name of each cog on the 1st page. Calling #each
# more than once will cause the 1st page to be printed for 
# each invocation.
cogs.each { |cog| puts cog.name }

# The next_page! method must be used to move to the 2nd page.
cogs.next_page!

# Print the name of each cog on the 2nd page
cogs.each { |cog| puts cog.name }





- Scope Example -------------------------------------------------------

# Get the second page of 'new' Cogs, using the #with_scope method. 
# Each page contains 15 cogs, and no more than 100 cogs will be returned.
Cog.with_scope(:find => {:conditions => "category = 'new'", :include => :widget}) do
  cogs = Cog.find(:all, 
                  :limit => 100,
                  :page => { :start => 1,
                             :current => 2,
                             :size => 15 })
end

# Print the name of each cog on the 2nd page.
cogs.each { |cog| puts cog.name }

# Move to the 3rd page of cogs. The options specified by 
# with_scope apply, even though a new page is loaded outside 
# the with_scope block.
cogs.next_page!


... more examples soon.


paginating_find's People

Contributors

alexkwolfe avatar

Stargazers

Angus H. avatar Daniel Benamy avatar foghost avatar  avatar Kyle Bragger avatar 404 avatar  avatar Tilo avatar  avatar Jamie Dyer avatar Joao Vitor Lacerda Guimaraes avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.