Follow them to show more results at the click of a button:
- Do not use the will_paginate tag in views
- Use AJAX to get the following set of results when clicking the following link
The following code will delete the page numbers and simply show the next and previous buttons:
<%= will_paginate @posts, :page_links => false %>
You can find more pagination styles here.
Edited using an AJAX sample :
1.Create a form with a page number as a hidden field
<%= form_tag url, :id => :filter, :method => :get do%> <%= hidden_field_tag :page, page %> <% end %>
2. Add a space for βMoreβ
<span class='more-results' >More</span>
3.Javascript functions for binding clicks and submitting an AJAX form
function bindMoreResults() { jQuery("span.more-results").unbind("click"); jQuery("span.more-results").click( function(e){ e.preventDefault(); getMoreResults(); }); } function getMoreResults() { jQuery('span.more-results').hide(); var page_value = parseInt(jQuery("form#filter #page").val()) + 1; jQuery("form#filter #page").val(page_value); var form = jQuery("form#filter"); jQuery.getJSON( form.attr("action") + ".json", form.serialize(), appendData ); } function appendData(data) { jQuery('span.more-results').show();
4.Modify appendData accordingly. More on getJSON: http://api.jquery.com/jQuery.getJSON/
source share