Skip to content

An example rails app using the will_paginate and flow_pagination gems together

Notifications You must be signed in to change notification settings

thisivan/flow_pagination_example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flow Pagination Example

An example rails app using the will_paginate and flow_pagination gems together

Requirements

Install

Checkout the sources:

git clone git://github.com/mexpolk/flow_pagination_example.git

Install the required gems, from the command line run:

sudo gem install haml
sudo gem install faker
sudo gem install populator
sudo gem install mexpolk-flow_pagination

Usage

Categories Controller

controllers/categories_controller.rb:

class CategoriesController < ApplicationController
  def index
    @categories = Category.paginate :page => params[:page], :order => 'name'
  end
end

Categories Index View

app/views/cateogories/index.html.haml:

= javascript_include_tag :all
%h1 Categories
%ul#categories= render @categories
= will_paginate @categories, :renderer => FlowPagination::LinkRenderer

Category Partial

app/views/categories/_category.html.haml:

%li{ :id => "category_#{category.id}" }=category.name

RJS Template

app/views/categories/index.js.rjs:

page.insert_html :bottom, :categories, :partial => @categories
page.replace :flow_pagination, will_paginate(@categories,
  :renderer => FlowPagination::LinkRenderer)

Populate Database

To test this solution I’ve created a rake task to populate the database (lib/tasks/populate.rake):

namespace :db do
  desc 'Erase and fill database'
  task :populate => :environment do

    require 'populator'
    require 'faker'

    Category.delete_all

    Category.populate 100 do |category|
      category.name = Populator.words(1..3).titleize
    end

  end
end

Enjoy

Run your application, browse your category listing (localhost:3000/categories). Go to the end of the page and, if you have more than 30 categories (or more than the number specified in the per_page parameter), you should see the “More” button. Click it and the next records will be added next to the previous ones.

Changing the Button’s Legend

FlowPagination supports internationalization (Rails i18n), thus you can change the label like this:

I18n.backend.store_translations :en, 'flow_pagination.button' => {  :default => 'Next Records' }

Another way to accomplish the same is to add the following in your locales (config/locales/en.application.yml):

en:
  flow_pagination:
    button: Next Records

Setting FlowPagination as Default LinkRenderer

If you wan’t to use FlowPagination::LinkRenderer as default, instead of specify the renderer parameter each call to WillPaginate helper, you can specify it on Application Helper (app/helpers/application_helper.rb):

module ApplicationHelper
  WillPaginate::ViewHelpers.pagination_options[:renderer] =
    FlowPagination::LinkRenderer
end

License

Copyright © 2008 Iván “Mexpolk” Torres

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

An example rails app using the will_paginate and flow_pagination gems together

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published