Neo4j Paginated - 未定义方法'total_pages'

时间:2015-02-14 17:44:25

标签: neo4j will-paginate neo4j.rb

我正在使用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>

错误是:未定义的方法`total_pages'代表# 不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

如果您使用的是will_paginate,则需要neo4j-will_paginate_redux gem,而不应直接使用Neo4j::Paginated课程。该类用于进行基本分页。 will_paginate需要一个WillPaginate::Collection对象。