Skip to content

Instantly share code, notes, and snippets.

@kapkaev
Forked from yrgoldteeth/_orders.html.erb
Created November 11, 2011 21:25
Show Gist options
  • Save kapkaev/1359331 to your computer and use it in GitHub Desktop.
Save kapkaev/1359331 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('<%= escape_javascript(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