Rails3/will_paginate/Ajax - 下一个/上一个链接无法正常工作(这是一个错误吗?)

发布于 2024-10-24 18:34:04 字数 1467 浏览 3 评论 0原文

我正在关注我的 Rails 3 应用程序的“Pagination with ajax”railscast。一切似乎都工作得很好,除了上一个和下一个链接根本不起作用这一事实。

基本上,

  • 即使我点击其他页面,上一个链接也会被卡住,(当我在用户/显示页面1上时)

  • “下一个链接”工作一次,直到第2页(之后我无法使用它)

  • 当我来到“...”时数字没有更新

我会很高兴知道是否有人遇到同样的问题(错误?)或者我的代码是否错误。 我使用 will paginate (“~> 3.0.pre2”和 jquery 1.8.10)来获取依赖于用户的微帖子列表。

非常感谢您的帮助!

这里的代码:

layout_helper.rb

module LayoutHelper
  def javascript(*args)
    content_for(:head) { javascript_include_tag(*args) }
  end
end

users_controller.rb

def show
    @user = User.find(params[:id])
    @microposts = @user.microposts.paginate(:per_page => 10, :page => params[:page])
end

microposts/_micropost.html.erb

...

users/show.html.erb

<% javascript "pagination" %>

...

<%= will_paginate @microposts %>
  <ul id="feed_items">
    <%= render @microposts %>
  </ul>

users/show.js.erb

$("#feed_items").html("<%= escape_javascript(render @microposts ) %>");

pagination.js

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

I am following the "Pagination with ajax" railscast for my rails 3 application. Everything seems to work great, except the fact that Previous and next links don't work at all.

Basically,

  • It appears that the previous link is stuck even if I click on other pages, (when I am on the user/show page1)

  • The "next link" works one time till the page 2 (I can't use it after)

  • Numbers didn't update when I come to "..."

I would be pleased to know if someone experience the same problem (a bug?) or if my code is wrong.
I use will paginate ("~> 3.0.pre2"and jquery 1.8.10) for a list of microposts dependent to users.

Thanks a lot for your help!

here the code:

layout_helper.rb

module LayoutHelper
  def javascript(*args)
    content_for(:head) { javascript_include_tag(*args) }
  end
end

users_controller.rb

def show
    @user = User.find(params[:id])
    @microposts = @user.microposts.paginate(:per_page => 10, :page => params[:page])
end

microposts/_micropost.html.erb

...

users/show.html.erb

<% javascript "pagination" %>

...

<%= will_paginate @microposts %>
  <ul id="feed_items">
    <%= render @microposts %>
  </ul>

users/show.js.erb

$("#feed_items").html("<%= escape_javascript(render @microposts ) %>");

pagination.js

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨离汐 2024-10-31 18:34:04

或者,如果您想坚持使用 will_paginate,有一个简单的修复方法。只需将您的辅助方法放入 div 中,如下所示:

<div id="page_links">
 <%= will_paginate @microposts %>
</div>

然后,在 js.erb 文件中将此行添加到末尾:

$('#page_links').html('<%= escape_javascript(will_paginate @microposts) %>');

无论如何,您已经传递了页面和所有正确的参数,因此这只会强制视图链接更新适当地。

Or, if you want to stick with will_paginate there's a simple fix. Just put your helper method in a div like so:

<div id="page_links">
 <%= will_paginate @microposts %>
</div>

Then, in your js.erb file add this line to the end:

$('#page_links').html('<%= escape_javascript(will_paginate @microposts) %>');

You're already passing page and all the right params there anyway, so this will just force the view links to update properly.

贪了杯 2024-10-31 18:34:04

我建议您查看 http://railscasts.com/episodes/254-pagination-with-雷

will_paginate 未更新以与 Rails 3 配合使用。

I suggest you look at http://railscasts.com/episodes/254-pagination-with-kaminari .

will_paginate is not updated to work with Rails 3.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文