0

i am trying to pagination with kaminari for first time and i got error:

views/store/index.html.erb where line #23 raised:

undefined method `current_page' for #<Array:0x3ebe0c0>

Extracted source (around line #23):

20:     </div>
21: </div>
22: <%end%>
23: <%= paginate @buildings %>

controller>buildings_controller

def index
    @buildings = Building.all.page(params[:page]).per(1)

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @buildings }
    end
  end

store>index

<%= paginate @buildings %>

what i am doing wrong??

marios
  • 153
  • 1
  • 14

2 Answers2

1

Remove the all in

@buildings = Building.all.page(params[:page]).per(1)

Like this

@buildings = Building.page(params[:page]).per(1)

And you are good to go.
The ActiveRecord all method returns an array, and i believe Kaminari don't expect an array to work.

MurifoX
  • 14,991
  • 3
  • 36
  • 60
  • thx for the help but actually is not working. after that gives me more and more error like the .per anw i have change the hole thing and now is working – marios Jul 26 '12 at 20:46
0

i have change the kaminari and i have use will_paginate and working like crazy!

in gemfile

gem 'will_paginate', '>= 3.0.pre'

in dash=> bundle install

in store>index

<%= will_paginate @buildings %>

in controller> store_controller

@buildings = Building.paginate :page=>params[:page], :order =>'created_at DESC', :per_page=>1

and done! your good to go with paginate

marios
  • 153
  • 1
  • 14