Search code examples
kaminarineo4j.rb

Neo4j.rb - undefined local variable or method `model' for #


Here is my controller:

  def index
    if params[:limit]
      @bisacs = Bisac.order(:bisac_code).page(params[:page]).per(params[:limit])
    else
      @bisacs = Bisac.order(:bisac_code).page(params[:page])
    end
  end

Here is my view:

<%= paginate @bisacs %>
<%= page_entries_info @bisacs %>

The error is:

undefined local variable or method `model' for #<Kaminari::Neo4j::Paginated:0x007ff2f211bf38>

For the line:

<%= page_entries_info @bisacs %>

What I am missing here?

But page_entries_info works when I am using this in the controller for other methods:

q = "
MATCH (b:Bisac)
WITH b, size((b)<-[:INCLUDED_IN]-()) as wokas_count
RETURN b.bisac_code as bisac_code, b.bisac_value as bisac_value, wokas_count, b.uuid as uuid
ORDER BY b.bisac_code
;"
@result = Neo4j::Session.current.query(q).to_a
if params[:limit]
  @result = Kaminari.paginate_array(@result).page(params[:page]).per(params[:limit])
else
  @result = Kaminari.paginate_array(@result).page(params[:page])
end

Here is more info about the error from the log file:

Started GET "/bisacs/d1d614a8-3c70-11e5-8eb8-22000b18b199" for 127.0.0.1 at 2015-08-12 12:49:58 -0400
Processing by BisacsController#show as HTML
  Parameters: {"id"=>"d1d614a8-3c70-11e5-8eb8-22000b18b199"}
 CYPHER 244ms MATCH (result_bisac:`Bisac`) WHERE (result_bisac.uuid = {result_bisac_uuid}) RETURN result_bisac ORDER BY result_bisac.uuid LIMIT {limit_1} | {:result_bisac_uuid=>"d1d614a8-3c70-11e5-8eb8-22000b18b199", :limit_1=>1}
 Bisac#wokas 217ms MATCH bisac24319681 WHERE (ID(bisac24319681) = {ID_bisac24319681}) MATCH bisac24319681<-[rel1:`INCLUDED_IN`]-(result_wokas:`Woka`) RETURN count(result_wokas) AS result_wokas | {:ID_bisac24319681=>24319681}
 Bisac#wokas 216ms MATCH bisac24319681 WHERE (ID(bisac24319681) = {ID_bisac24319681}) MATCH bisac24319681<-[rel1:`INCLUDED_IN`]-(result_wokas:`Woka`) RETURN count(result_wokas) AS result_wokas | {:ID_bisac24319681=>24319681}
  Rendered bisacs/show.html.erb within layouts/application (239.6ms)
Completed 500 Internal Server Error in 707ms

ActionView::Template::Error (undefined local variable or method `model' for #<Kaminari::Neo4j::Paginated:0x007fad5de0ad28>):
    18:   <%= select_tag :limit, options_for_select([5, 10, 15, 20, 25, 30], selected: params[:limit] || 25) %>
    19: <% end %>
    20: <%= paginate @wokas %>
    21: <%= page_entries_info @wokas %>
    22: 
    23: <table>
    24:   <thead>
  app/views/bisacs/show.html.erb:21:in `_app_views_bisacs_show_html_erb___1469171013071285334_70191290534340'


  Rendered /Users/levi/.rbenv/versions/2.2.1/lib/ruby/gems/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (5.6ms)

Solution

  • Changed the index method to use paginate_array.

      def index
        if params[:limit]
          @bisacs = Kaminari.paginate_array(Bisac.order(:bisac_code).to_a).page(params[:page]).per(params[:limit])
        else
          @bisacs = Kaminari.paginate_array(Bisac.order(:bisac_code).to_a).page(params[:page])
        end
      end
    

    And got the

    <%= page_entries_info @bisacs %>
    

    working.