Rails Kaminari Pagination using Ajax

1.8k Views Asked by At

I'm having troubles paginating using Ajax. My View code looks for pagination looks like

= paginate @products, :remote => true

However, the AJAX call fails with error status code and Web Inspector shows it as seen below enter image description here

The server logs show

ERROR Errno::ECONNRESET: Connection reset by peer
/Users/user/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `eof?'
/Users/user/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:56:in `run'
/Users/user/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

What is interesting though is if I add a hyperlink to the same page like

= link_to('Test', products_path(:page => 2), :remote => true)

The link look exactly like the one generated by Kaminari and the Ajax call succeeds without any issues whatsoever. More interesting, if I change generated pagination link from

<a href="/brands/deborah-lippmann" data-remote="true" rel="prev">1</a>

to

<a href="/brands/deborah-lippmann" data-remote="true">1</a>

which has nothing to do with AJAX, the link works fine again.

Is it something to do with jquery-ujs magic happening before links are rendered by Kaminari which uses ActionView Extensions and ActionView Context to generate tags for pagination links? Any help on this issue is greatly appreciated!

1

There are 1 best solutions below

0
On

Chek /app/views/layouts/application.html.erb for next lines

<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>