Rails3/will_paginate/Ajax - 下一个/上一个链接无法正常工作(这是一个错误吗?)
我正在关注我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或者,如果您想坚持使用 will_paginate,有一个简单的修复方法。只需将您的辅助方法放入 div 中,如下所示:
然后,在 js.erb 文件中将此行添加到末尾:
无论如何,您已经传递了页面和所有正确的参数,因此这只会强制视图链接更新适当地。
Or, if you want to stick with will_paginate there's a simple fix. Just put your helper method in a div like so:
Then, in your js.erb file add this line to the end:
You're already passing page and all the right params there anyway, so this will just force the view links to update properly.
我建议您查看 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.