Skip to content

Instantly share code, notes, and snippets.

@gonzedge
Created November 10, 2011 16:08
Show Gist options
  • Save gonzedge/1355231 to your computer and use it in GitHub Desktop.
Save gonzedge/1355231 to your computer and use it in GitHub Desktop.
Rails 3.1 - will_paginate and ajax
<ul>
<% @orders.each do |order| %>
<li>
<!-- Show order stuff -->
</li>
<% end %>
</ul>
<%= will_paginate @orders %>
$('#orders').html('<%= render partial: 'orders' %>');
$.setAjaxPagination();
<div id="orders">
<%= render partial: 'orders' %>
</div>
<div id="orders">
<ul>
<% @orders.each do |order| %>
<li>
<!-- Show order stuff -->
</li>
<% end %>
</ul>
<%= will_paginate @orders %>
</div>
$ ->
$.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()
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
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