Each webpage can have multiple ajax_section containers, whether they are side by side, or even nested. Links can reference an ajax_section to load new content into the section using AJAX. Watch as the URL in the browser address bar updates, with fully working back/forward buttons.
For more, see Introduction and Background.
This gem requires Rails 3.0+. When using the asset pipeline in Rails 3.1+, follow the general installation instructions. Otherwise, use the ajax_pagination:assets generator, which puts the assets into the public/ directory.
|To see this gem in action, watch the demonstration video, as shown left. It shows a built-in animation on loading, fully working history and AJAX requests which can perform POST and DELETE requests, whether via a link or a form submission and redirects.|
Assuming, you are using the asset pipeline, add to your Gemfile:
and run the bundle install command.
Then add ajax_pagination to your asset manifests,
/* app/assets/stylesheets/application.css *= require ajax_pagination */
To use this on Rails 3.0, or without using the asset pipeline, read the Installation without the Asset Pipeline guide.
In the ActionView, use ajax_section to declare a section, and ajax_link_to to create a link loading content into the section:
<%= ajax_link_to "Link", link_url, :section_id => "section_name" %> <%= ajax_section :id => "section_name", :render => "mypartial" %>
Then, in the ActionController, use ajax_respond to render only the partial when an AJAX request is made:
Class ObjectsController < ApplicationController def index ... respond_to do |format| format.html # index.html.erb ajax_respond format, :section_id => "section_name", :render => "_mypartial" end end ... end
Much more information can be found in the wiki.
To learn how to use this gem, read one of the usage guides below (found in the wiki):
For more, including how specific features work, look in the wiki.
Alternatively, to see the API, see RDoc.
- Supports multiple and nested sections
- Supports browser history, for more see Robust Support for Browser History in AJAX Pagination
- Supports links, but also POST, DELETE, PUT links and forms, which can all be used to change the content in a section
- Supports redirects - a necessary feature when used with forms
- Built in visual cues when loading new content - can be altered with css.
This gem contains an example application (actually, it is there also for testing purposes), however it is nevertheless a good example.
Clone this repository, and run the server, using:
git clone git://github.com/ronalchn/ajax_pagination.git cd ajax_pagination cd spec/rails_app bundle install bundle exec rails server
Then point your browser to http://localhost:3000/
As well as the included ajax_pagination.js file, this gem uses jquery.ba-bbq.js and jquery.url.js, which are jquery plugins. They are included in the gem as assets already to simplify installation. ajax_pagination.js will automatically require jquery.ba-bbq.js, and jquery.url.js.
You are welcome to submit pull requests on GitHub at https://github.com/ronalchn/ajax_pagination, however, please be aware that submitting a pull request is assumed to grant to me non-exclusive, perpetual rights to the use of the software for any use whatsoever. This allows me to release the software under a more permissible license in the future if I want.
If you do not submit a pull request, your modifications will not be merged into the codebase.
Copyright © 2012 Ronald Ping Man Chan
If you want to use this program under a different license, please contact me. All pull requests to my repository will be assumed to assign to me non-exclusive rights for perpertual usage for any use whatsoever for those modifications to Ronald Ping Man Chan. If you do not have the power to assign that right, do not submit a pull request. This allows me to release the software under a more permissible license in the future if I want. Ronald
The software is released under LGPL. This means that this Gem can be used in any software (proprietary or otherwise), by using the gem command for installation. However, the gem cannot be included directly in proprietary software (eg. as a plugin), without distributions of the software being under LGPL. Distribution of this Gem may only be released under a license LGPL is compatible with.