使用 Ajax 的 Rails Kaminari 分页
我在使用 Ajax 进行分页时遇到问题。我的视图代码看起来分页看起来像
= paginate @products, :remote => true
但是,AJAX 调用失败并显示错误状态代码,Web Inspector 显示如下所示
服务器日志显示
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'
有趣的是,如果我向同一页面添加一个超链接,例如
= link_to('Test', products_path(:page => 2), :remote => true)
链接的外观与 Kaminari 生成的完全一样,Ajax 调用成功,没有任何问题。更有趣的是,如果我将生成的分页链接更改为
<a href="/brands/deborah-lippmann" data-remote="true" rel="prev">1</a>
。
<a href="/brands/deborah-lippmann" data-remote="true">1</a>
与 AJAX 无关的链接,该链接将再次正常工作
这是否与 Kaminari 渲染链接之前发生的 jquery-ujs 魔法有关,Kaminari 使用 ActionView 扩展和 ActionView 上下文来生成分页链接的标签?非常感谢有关此问题的任何帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Chek /
app/views/layouts/application.html.erb
获取下一行Chek /
app/views/layouts/application.html.erb
for next lines