will_paginate 分页在 AJAX 刷新时呈现两次

will_paginate pagination is rendered twice on AJAX refresh

我正在 Rails 4.2.2 中编写应用程序。在我看来,我正在为 search/sort 使用 filterrific gem。我的列表部分有 will_paginate:

<div>
  <%= page_entries_info @work_items, model: 'work items' %>
</div>
<%= will_paginate %>
<div id="filterrific_results">
  <div>
  </div>

  <table class="table table-bordered table-hover work_item_list_table">
    <tr>
      <th>Phone Number</th>
      <th>Customer Name</th>
      <th>Twitter</th>
      <th>Account number</th>
      <th>Notes</th>
      <th>Age</th>
    </tr>
    <% work_items.each do |work_item| %>
      <tr>
        <td><%= link_to work_item.phone, work_item_path(work_item)%></td>
        <td><%= work_item.customer_name %></td>
        <td><%= work_item.twitter %></td>
        <td><%= work_item.account %></td>
        <td><%= truncate(work_item.notes, length: 300, separator: ' ') %></td>
        <td><%= time_ago_in_words(work_item.created_at) %> old, submitted at:<br />
            <%= work_item.created_at.strftime("%I:%M%p on %A, %B %e %Y") %></td>
      </tr>
    <% end %>
  </table>
</div>
<%= will_paginate %>

每当我更改过滤器选项并刷新列表时,我的分页就会双重呈现:

http://i.stack.imgur.com/IrlHW.jpg

我的 index.js.erb 和 work_items_controller.rb 如下,或多或少直接取自 filterrific 示例应用程序(其中他们还使用 will_paginate gem 进行分页没有这样的问题):

<% js = escape_javascript(
  "render(partial: 'work_items/list', locals: { work_items: @work_items })
) %>
$("#filterrific_results").html("<%= js %>");

  def index
    @filterrific = initialize_filterrific(
      WorkItem,
      params[:filterrific],
      select_options: {
        sorted_by: WorkItem.options_for_sorted_by,
        completion_status: WorkItem.options_for_completion_status,
        needs_contact: WorkItem.options_for_needs_contact
      },
      persistence_id: 'shared_key',
      ) or return

    @work_items = @filterrific.find.page(params[:page])

    respond_to do |format|
      format.html
      format.js
    end

  end

我的index.html.erb如下:

<% provide(:title, "All work items") %>
<h1>All work items</h1>

<div class="row">
  <div class="well">
    <%= form_for_filterrific @filterrific, html: { class: "form-inline" } do |f| %>

      <div class="form-group">
        <%= f.label :search, class: "sr-only" %> 
        <%= f.text_field(:search_query, class: 'form-control filterrific-periodically-observed work-item-search-box', placeholder: "Search") %>
      </div>

      <div class="form-group">
        <%= f.label :sorted_by %> 
        <%= f.select(:sorted_by, @filterrific.select_options[:sorted_by], {}, class: 'form-control' ) %>
      </div>

      <div class="form-group">
        <%= f.label :status %> 
        <%= f.select(:completion_status, @filterrific.select_options[:completion_status],
        { include_blank: "All" }, class: 'form-control') %>
      </div>

      <div class="form-group">
        <%= f.label :needs_contact %>
        <%= f.select(:needs_contact, @filterrific.select_options[:needs_contact],
        { include_blank: "All" }, class: 'form-control') %>
      </div>

      <div class="form-group">
        <%= link_to('Reset filters', reset_filterrific_url, class: "btn btn-default") %>
      </div>

      <%= render_filterrific_spinner %>
    <% end %>
  </div>
</div>
<div class="row">
  <div class="well">
    <%= render partial: 'work_items/list', locals: { work_items: @work_items } %>
  </div>
</div>

无论我是否有两个 will_paginate,它都会发生。如果我将 will_paginate 放在部分之外,当 AJAX 刷新命中时它不会刷新。关于如何消除这种情况的任何想法?

我找到问题了!我的分页超出了我的#filterrific-results div,因此 index.js.erb 没有正确刷新。