Giter Club home page Giter Club logo

will_paginate's Introduction

will_paginate

This version of will_paginate is optimized for Rails 5 on Ruby 2.2+ and compatibility with the Ransack search gem:

  • Strings are now frozen to be immutable, to reduce object allocations and memory use.
  • Rails 5 composes ActionController::Parameters as a HWIA instead of inheriting from Hash. Ransack needs nested options hashes in AC::Parameters to be parsed correctly. This is handled here.
  • Legacy code for Rails 2 and 3 and Merb was removed to make the gem more lightweight.

Installation:

gem 'will_paginate', github: 'jonatack/will_paginate'

Basic use

In the controller:

  # perform a paginated query
  @posts = Post.paginate(page: params[:page])

  # use an explicit "per page" limit
  Post.paginate(page: params[:page], per_page: 30)

  # will_paginate returns a chainable Active Record relation
  Post.where(published: true).paginate(page: params[:page]).order(id: :desc)

  # the new, shorter #page method
  Post.page(params[:page]).order(created_at: :asc)

In the view, to render pagination links:

  <%= will_paginate @posts %>

And that's it! You just need to add some CSS styles to make those pagination links prettier.

You can customize the default "per_page" value:

  # for the Post model
  class Post
    self.per_page = 10
  end

  # set per_page globally
  WillPaginate.per_page = 10

Happy paginating! ❤️

will_paginate's People

Contributors

mislav avatar jonatack avatar metaskills avatar nathany avatar poporul avatar benpickles avatar chriseppstein avatar denis avatar edariedl avatar kamal avatar kjg avatar mattetti avatar useruby avatar bryanlarsen avatar chandresh avatar dnrce avatar flyingmachine avatar danielvartanov avatar dbackeus avatar dhh avatar dejan avatar fabioyamate avatar phene avatar gcirne avatar epid avatar jingoro avatar jordimassaguerpla avatar l-schirrmeister avatar flink avatar marcgg avatar

Watchers

James Cloos avatar Tyler Sampson 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.