Giter Club home page Giter Club logo

will_paginate_infinite's Introduction

will_paginate_infinite

gem version

Will Paginate with infinite scroll for Rails

Instalation

Include the gem in your Gemfile:

gem 'will_paginate_infinite'

And then execute:

$ bundle install

Adds to app/assets/stylesheets/application.scss:

*= require will_paginate_infinite

And javascript to app/assets/javascripts/application.js:

//= require will_paginate_infinite

Configuration

In your index view pagination :

# app/views/news/index.html.erb
<h1>News List</h1>

<div class="list-news">
  <ul>
    <% @news.each do |item| %>
      <%= render item %>
    <% end %>
  </ul>

  <%= will_paginate @news, renderer: WillPaginateInfinite::InfinitePagination %>
</div>

Will paginate renderer: WillPaginateInfinite::InfinitePagination

In content partial view:

# app/views/news/_news.html.erb
<li>
  <%= item.title %>
</li>

And in controller/action with items to be paginated:

# app/controllers/news_controller.rb
class NewsController < ApplicationController
  def index
    @news = News.order(:created_at).paginate(:page => params[:page], :per_page => 30)
    # ...

    respond_to do |format|
      format.html
      format.js
    end
  end
end

Creates a javascript version from your index view:

# app/views/news/index.js.erb
<%= infinite_append ".list-news ul", @news %>

or

# app/views/news/index.js.erb
<%= infinite_append ".list-news ul", { partial: "news/news", collection: @news }  %>

Example

Example using will_paginate_infinite with Rails 4: https://github.com/Godoy/will_paginate_infinite_example

Contributing

  1. Fork it (https://github.com/PlanBCom/will_paginate_infinite/fork).
  2. Create your feature branch (git checkout -b my-new-feature).
  3. Commit your changes (git commit -am 'Add some feature').
  4. Push to the branch (git push origin my-new-feature).
  5. Create a new Pull Request.

will_paginate_infinite's People

Contributors

collectiveaccess avatar godoy avatar mohamedalaa avatar

Watchers

 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.