I am using will_paginate gem in my ROR project to show the records in pages.
I want the next page to be loaded without reloading the whole
You could just use JQuery:
Controller:
def index
@posts = Post.paginate(:page => params[:page])
respond_to do |format|
format.html
format.js
end
end
Then in index.html.erb:
<%= j render 'post_content' %>
In partial '_post_content.html.erb':
<%= will_paginate @posts %>
<% @posts.each do |post| %>
<%= post.content %>
<% end %>
pagination.js:
$(document).ready(function() {
$('.pagination > a').attr('data-remote', 'true');
});
index.js.erb:
$('#post-content').html("<%= j render 'post_content' %>")
Make sure to add the
$('.pagination > a').attr('data-remote', 'true');
again in your JS template (index.js.erb), so it sets the links data-remote again when the Ajax runs.