-
-
Save kapkaev/1359331 to your computer and use it in GitHub Desktop.
Rails 3.1 - will_paginate and ajax
This file contains 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
<ul> | |
<% @orders.each do |order| %> | |
<li> | |
<!-- Show order stuff --> | |
</li> | |
<% end %> | |
</ul> | |
<%= will_paginate @orders %> |
This file contains 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
$('#orders').html('<%= escape_javascript(render partial: 'orders') %>'); | |
$.setAjaxPagination(); |
This file contains 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="orders"> | |
<%= render partial: 'orders' %> | |
</div> |
This file contains 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="orders"> | |
<ul> | |
<% @orders.each do |order| %> | |
<li> | |
<!-- Show order stuff --> | |
</li> | |
<% end %> | |
</ul> | |
<%= will_paginate @orders %> | |
</div> |
This file contains 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
$ -> | |
$.setAjaxPagination = -> | |
$('.pagination a').click (event) -> | |
event.preventDefault() | |
loading = $ '<div id="loading" style="display: none;"><span><img src="/assets/loading.gif" alt="cargando..."/></span></div>' | |
$('.other_images').prepend loading | |
loading.fadeIn() | |
$.ajax type: 'GET', url: $(@).attr('href'), dataType: 'script', success: (-> loading.fadeOut -> loading.remove()) | |
false | |
$.setAjaxPagination() |
This file contains 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 OrdersController < ApplicationController | |
def index | |
@orders = Order.paginate(page: params[:page], per_page: 10) | |
respond_to do |format| | |
format.html | |
format.js | |
end | |
end | |
end |
This file contains 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 OrdersController < ApplicationController | |
def index | |
@orders = Order.paginate(page: params[:page], per_page: 10) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment