简体   繁体   English

在Rails 3.1中的Ajaxify will_paginate

[英]Ajaxify will_paginate in rails 3.1

I am trying to ajaxify will_paginate result in rails 3.1. 我正在尝试在rails 3.1中使will_paginate结果无效。 I have gone through the example of railscasts episode #174 but it is not working for rails 3.1. 我已经看过Railscasts第174集的示例,但是它不适用于Rails 3.1。

Is there a simple way to ajaxify will_paginate result in rails3.1? 有没有一种简单的方法可以在rails3.1中对will_paginate结果进行ajax处理?

Here is index.js.erb code for loading the user partial (this file is in app/views/users folder) $('#test').html("<%= escape_javascript(render(@users)) %>" ); 这是用于加载用户部分内容的index.js.erb代码(此文件位于app / views / users文件夹中) $('#test').html("<%= escape_javascript(render(@users)) %>" );

Here is my pagination.js code (this file is in app/assets/javascripts) 这是我的pagination.js代码(此文件位于app / assets / javascripts中)

  $(function() {
  $(".users a").live("click", function() {
    $.get(this.href, null, null, "script");
    return false;
  });
  });

I am using will_paginate both the files are getting loaded and I have tested for it. 我正在使用will_paginate这两个文件都已加载,并且已经对其进行了测试。

Any help on where I am making the mistake? 对我犯错的地方有帮助吗?

Thanks, 谢谢,

replace the line in pagination.js : 替换pagination.js中的行:

$(".users a").live("click", function() {

with

$(".pagination a").live("click", function() {

Then just make sure your index.js.erb is named correctly. 然后只要确保您的index.js.erb命名正确即可。 For example, if you're using pagination inside the view show.html.erb , your script has to be named show.js.erb 例如,如果在视图show.html.erb中使用分页,则脚本必须命名为show.js.erb。

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

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