简体   繁体   English

使用Ajax的Rails Kaminari分页

[英]Rails Kaminari Pagination using Ajax

I'm having troubles paginating using Ajax. 我在使用Ajax进行分页时遇到麻烦。 My View code looks for pagination looks like 我的View代码看起来像分页一样

= paginate @products, :remote => true

However, the AJAX call fails with error status code and Web Inspector shows it as seen below 但是,AJAX调用失败并显示错误状态代码,并且Web Inspector如下所示显示它 在此处输入图片说明

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. 链接看起来完全像是Kaminari生成的链接,Ajax调用成功了,没有任何问题。 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. 与AJAX无关,则链接可以再次正常运行。

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? 这是与Kaminari渲染链接之前发生的jquery-ujs魔术有关的吗,Kaminari使用ActionView扩展和ActionView上下文为分页链接生成标签? Any help on this issue is greatly appreciated! 非常感谢在此问题上的任何帮助!

Chek / app/views/layouts/application.html.erb for next lines Chek / app/views/layouts/application.html.erb以获取下一行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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