1

我正在使用 Neo4j 数据库,我的 Author 类包括 ActiveNode。我正在寻找带有分页的索引。这是控制器和作者的索引:

class AuthorsController < ApplicationController
  before_action :set_author, only: [:show, :edit, :update, :destroy]
  # GET /authors
  # GET /authors.json
  def index
    @page = params[:page] || 1
    @per_page = params[:per_page] || WillPaginate.per_page
    @query = Author.all.order("name")
    @authors = Neo4j::Paginated.create_from(@query, @page, @per_page)
  end
...
end

<div class="container-fluid">
  <h1>Listing authors</h1>

  <ul><%= will_paginate @authors, class: "pagination-sm" %></ul>
  <%= select_tag :per_page, options_for_select([10,20,40,80,100], @per_page.to_i), :onchange => "if(this.value){window.location='?per_page='+this.value;}" %>

  <table>
    <thead>
      <tr>
        <th>Name</th>
        <th colspan="3">Action</th>
      </tr>
    </thead>

    <tbody>
      <% @authors.each do |author| %>
        <tr>
          <td><%= author.name %></td>
          <td><%= link_to 'Show', author, class: 'btn btn-xs btn-primary' %></td>
          <td><%= link_to 'Edit', edit_author_path(author), class: 'btn btn-xs btn-primary' %></td>
          <td><%= link_to 'Destroy', author, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-xs btn-danger' %></td>
        </tr>
      <% end %>
    </tbody>
  </table>

  <br>
  <div class="btn-toolbar">
    <%= link_to 'New Author', new_author_path, class: 'btn btn-xs btn-primary' %>
    <%= link_to 'Books', books_path, class: 'btn btn-xs btn-primary' %>
    <%= link_to 'Home', root_path, class: 'btn btn-xs home-btn' %>
  </div>
</div>

错误是: undefined method `total_pages' for # 不知道如何解决这个问题。

4

1 回答 1

1

如果您正在使用will_paginate,则需要neo4j-will_paginate_redux gem,并且不应Neo4j::Paginated直接使用该类。该类用于进行基本的分页。will_paginate期望一个WillPaginate::Collection对象。

于 2015-02-14T23:01:26.143 回答