Skip to content

Instantly share code, notes, and snippets.

@bcalloway
Created November 23, 2009 16:27
Show Gist options
  • Save bcalloway/241153 to your computer and use it in GitHub Desktop.
Save bcalloway/241153 to your computer and use it in GitHub Desktop.
Ajax pagination
// app/views/users/_results.html.haml
%table.table
- @users.each do |user|
%tr
%td
= h user.name
%td
= link_to 'Show', user
|
= link_to 'Edit', edit_user_path(user)
|
= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete
= will_paginate :renderer => 'RemoteLinkRenderer', :remote => {:update => 'all-events', :loading => "$('#spinner').show()", :complete => "$('#spinner').hide()"}
// This assumes there is an animated gif named "spinner.gif" in the images directory
// app/views/users/index.html.haml
= image_tag("spinner.gif", :align => "absmiddle", :border => 0, :id => "spinner", :style =>"display: none;" )
#all-results
= render 'results'
# app/models/user.rb
def self.all_users(page)
paginate(:page => page, :per_page => 10)
end
# app/controllers/users_controller.rb
def index
@users = User.all_users(params[:page])
respond_to do |format|
format.html
format.js { render :partial => 'results' }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment