Problem while using will_paginate and ajax together

I’m using ruby on rails 6.0.3 and ruby 2.7 using will paginate gem, but this time i am facing a problem. I have to use will_paginate with ajax call, means the page shouldn’t reload when i click on the navigation link. I searched about this topic on many sites, didn’t get any help, I hope will find the solution here

1 Like

I would think that when you setup turbolinks in your Rails app, the will_paginate form will automatically emit AJAX requests instead of full-page loads.

1 Like

If you’re using ajax, you’ll likely have some js.erb file. The fix is very simple to make will_paginate work with ajax. You need to do this in your js.erb file

# render the table and the will_paginate's pagination div
# then you need to run the following line
$('.pagination a').attr('data-remote', 'true');

This will make the pagination links work with ajax calls.