2

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!

Community
  • 1
  • 1
membLoper
  • 1,972
  • 19
  • 21
  • What is the javascript error you are getting? It's showing `undefined` on line 7951 of `application.js`... If no request is being received by the server, then it must be a javascript issue. – iwasrobbed Jan 25 '12 at 20:59
  • 1
    There was no javascript error in console. The line 7951 of application.js is actually thick of jquery which 'creates transport if the browser can provide an xhr' and the actual code is https://gist.github.com/dc87f34e1523a511fae7 – membLoper Jan 26 '12 at 02:17
  • Is that all that's contained in the server log? Can you see what request was made that led to the error? – Ryan Feb 04 '12 at 21:36
  • do you have <%= csrf_meta_tags %> in your layout ? see this http://www.slideshare.net/adamlogic/jquery-and-rails-sitting-in-a-tree – Fivell Feb 06 '12 at 14:57
  • maybe this can help you.. http://stackoverflow.com/questions/6134028/jquery-rails-breaks-kaminari – patie Mar 19 '13 at 18:14

1 Answers1

0

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

<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
Fivell
  • 11,829
  • 3
  • 61
  • 99