删除带分页栏的记录

时间:2018-04-21 15:05:38

标签: ruby-on-rails pagination

我有分页的索引页(表)(使用will_paginate gem)我有删除操作(脚本调用),我需要更新ajax成功的分页链接,我想要删除操作的ajax调用以便有过滤器选项在页面中保留(根据日期范围和记录类型过滤记录)

<%= will_paginate collection, previous_label: "", next_label: "", page_links:false %> <%= page_entries_info collection %>

删除操作后我已将表体替换为未删除的记录,我不知道如何更改分页链接(修改分页链接与上一页并显示该页面中记录的当前页码) ,我也拒绝了will_paginate选项中记录的id,以防止对show动作的get调用(在删除和点击分页链接后添加id时)

1 个答案:

答案 0 :(得分:0)

假设您的索引将具有这样的分页:

# app/helpers/paginations_helper
def my_pagination(collection)
  will_paginate(collection) + page_entries_info(collection)
end

# index.html.erb
# ...
<div id="my-pagination">
  <%= my_pagination @collection %>
</div>

使用remote: true删除后,Rails会调用destroy.js.erb,因此您可以替换新的分页:

# destroy.js.erb
$('#my-pagination').html('<%= j my_pagination(@collection) %>');
相关问题