jQuery.pageless in Rails 3 with demo application
I am trying to integrate jQuery.pageless plugin in my application, but in vain. Can anyone provide me with some resource that shows a Rails 3 demo application that has jQuery.pageless working?
I tried looking into the example application that is provided with the plugin, which is in Rails 2.2. I tried to implement everything in a similar manner, but I get the error undefined method 'total_pages' for Array <....>, which is the array of one of my models.
Here's the code snippets:
module ApplicationHelper
def pageless(total_pages, url=nil, container=nil)
opts = {
:totalPages => total_pages,
:url => url,
:loaderMsg => 'Loading more results'
}
container && opts[:container] ||= container
javascript_tag("$('#results').pageless(#{opts.to_json});")
end
end
controller
def index
@posts = Post.all
if request.xhr?
sleep(3) # make request a little bit slower to see loader :-)
render :partial => "shared/post", :collection => @posts
end
end
view
<div id="recent-sale-item-area">
<% if !@posts.nil? %>
<p id="recent-posts"> recent posts </p>
开发者_如何学C <div id="recent-sale-item-list">
<%= render :partial => "shared/post", :collection => @posts %>
</div>
<%= will_paginate(@posts) %>
<%= pageless(@posts.total_pages, posts_path) %>
<% end %>
</div>
The Github page for jQuery.pageless has what you want:
https://github.com/jney/jquery.pageless
EDIT:
Your error is because Rails 3 no longer has pagination built-in. You will need to download the will_paginate or some other pagination gem, or roll your own.
精彩评论