简体   繁体   中英

Rails Kaminari Pagination using Ajax

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 在此处输入图片说明

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!

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM