Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save yannvery/7463886 to your computer and use it in GitHub Desktop.

Select an option

Save yannvery/7463886 to your computer and use it in GitHub Desktop.

Revisions

  1. yannvery revised this gist Dec 10, 2013. 8 changed files with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions 0_Paginate_without_reload_all_page_with_kaminari.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    # Paginate with Kaminari without reload all data

    Use :remote => true option on link_to and paginate Region index page
    File renamed without changes.
    File renamed without changes.
  2. yannvery revised this gist Dec 10, 2013. 7 changed files with 0 additions and 0 deletions.
  3. yannvery revised this gist Nov 14, 2013. 7 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  4. yannvery revised this gist Nov 14, 2013. 5 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
  5. yannvery renamed this gist Nov 14, 2013. 1 changed file with 0 additions and 0 deletions.
  6. yannvery created this gist Nov 14, 2013.
    1 change: 1 addition & 0 deletions gemfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    gem 'kaminari'
    8 changes: 8 additions & 0 deletions paginate_regions_controller.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    class PaginateRegionsController < ApplicationController

    def index
    @current_page = params[:page]
    @regions = Region.page(@current_page).per(10)
    end

    end
    36 changes: 36 additions & 0 deletions paginate_regions|_index.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    <div class="row">
    <div class="col-xs-12">
    <div class="widget-box">
    <div class="widget-title">
    <span class="icon">
    <i class="icon-screenshot"></i>
    </span>
    <h5>Regions</h5>
    </div>
    <div class="widget-content">
    <div class="span6"><%= link_to 'New Region', new_region_path, :class => "btn btn-primary" %></div>
    </div>
    <div class="widget-content nopadding">

    <table class="table table-bordered table-striped table-hover">
    <thead>
    <tr>
    <th>Id</th>
    <th>Name</th>
    </tr>
    </thead>
    <tbody>
    <% @regions.each do |region| %>
    <tr>
    <td><%= region.id %></td>
    <td><%= link_to region.name, region %></td>
    </tr>
    <% end %>
    </tbody>
    </table>
    <%= link_to 'Previous', paginate_regions_path(:page => @regions.current_page - 1), :remote => true unless @regions.first_page? %> |
    <%= link_to 'Next', paginate_regions_path(:page => @regions.current_page + 1), :remote => true unless @regions.last_page? %>
    </div>
    </div>
    </div>
    </div>
    2 changes: 2 additions & 0 deletions paginate_regions|index.js.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    $('#regions').empty();
    $('#regions').append('<%= escape_javascript(render partial: 'index') %>');
    8 changes: 8 additions & 0 deletions regions_controller.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    class RegionsController < ApplicationController

    def index
    @current_page = 1
    @regions = Region.page(@current_page).per(10)
    end

    end
    11 changes: 11 additions & 0 deletions regions|index.html.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    <div id="content-header">
    <h1>Regions</h1>
    </div>

    <div id="breadcrumb">
    <%= link_to raw('<i class="icon-home"></i> Home'), root_path, :class => "tip-bottom", "data-original-title" => "Go to Home" %>
    <a href="#" class="current">Regions</a>
    </div>
    <div id="regions">
    <%= render "paginate_regions/index" %>
    </div>
    1 change: 1 addition & 0 deletions routes.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    resources :paginate_regions, :only => [:index]