Use :remote => true option on link_to and paginate Region index page
Last active
November 3, 2022 11:11
-
-
Save yannvery/7463886 to your computer and use it in GitHub Desktop.
How to paginate on an ajax way ( with jquery and kaminari )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'kaminari' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RegionsController < ApplicationController | |
def index | |
@current_page = 1 | |
@regions = Region.page(@current_page).per(10) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PaginateRegionsController < ApplicationController | |
def index | |
@current_page = params[:page] | |
@regions = Region.page(@current_page).per(10) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#regions').empty(); | |
$('#regions').append('<%= escape_javascript(render partial: 'index') %>'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources :paginate_regions, :only => [:index] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment