[英]Replace will_paginate links after ajax call
I'm working on a Ruby on Rails aplicattion, my problem is that I have all the comments of a post paginated and showed perfectly, but when an user saves a new comment via ajax, and I replace all the content with the partial with the new content(including the will_paginate @comments), the urls of the links change to the url of the action that saves the comments and i don't know how to do to make them link correctly. 我正在使用Ruby on Rails应用程序,我的问题是我已将帖子的所有评论分页并完美显示,但是当用户通过ajax保存新评论时,我用新内容(包括will_paginate @comments),链接的url更改为保存评论的操作的url,我不知道如何使它们正确链接。
I tried with <%= will_paginate @comments, :params => {:controller => 'posts', :action => 'show_outside_comments' %>
But I get the same results. 我尝试使用
<%= will_paginate @comments, :params => {:controller => 'posts', :action => 'show_outside_comments' %>
但我得到了相同的结果。
Thank you very much for your help! 非常感谢您的帮助!
Have you looked into the ajax methods described here? 您是否研究过此处描述的Ajax方法?
http://railscasts.com/episodes/174-pagination-with-ajax http://railscasts.com/episodes/174-pagination-with-ajax
you can execute javascript code to update the links, something like: 您可以执行javascript代码来更新链接,例如:
<div class="paging_links" >
<%= will_paginate @comments, :params => {:controller => 'posts', :action => 'show_outside_comments' %>
</div>
<script type="text/javascript">
jQuery('.paging_links a').click(function(event){
href = jQuery(this).attr('href');
event.preventDefault();
// update href here
})
</script>
$('.pagination a').attr('href', function() {
$(this).prop('href').replace('/comments', location.pathname);
});
Assuming you want to replace `/comments' with the current pathname. 假设要用当前路径名替换“ / comments”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.