2

I have three relevant models. A User which has_many :photos and belongs_to :dorm, a Dorm which has_many :users and has_many :photos, :through => :users, and a Photo class which belongs_to :users and belongs_to :dorm.

I want to paginate all the photos that are in a dorm with kaminari. I have it in my Gemfile and ran the bundle command.

In my dorms_controller:

@dorm=Dorm.find(params[:id])
@photos=@dorm.photos.page(params[:page]).per(3)

and in my Dorm show view (actually in a partial, _index.html.erm rendered in the show view):

<%= paginate @photos %>

This gives me the error: undefined method 'page' for #<Class:0x107483d68>.

I know why this doesn't work (shouldn't be called on a class), but I don't know how to make it work...

Rymo4
  • 461
  • 2
  • 7
  • 15

2 Answers2

1

hrm, strange. That should work. I actually made a vanilla app with an action you shown above and the following models, but I couldn't reproduce the error.

class Dorm < ActiveRecord::Base
  has_many :users
  has_many :photos, :through => :users
end

class User < ActiveRecord::Base
  belongs_to :dorm
  has_many :photos
end

class Photo < ActiveRecord::Base
  belongs_to :user
end

There should be another root cause in your app code. So, could you track down the problem a bit more? To begin with, does the following code work in your rails console?

@dorm.photos.page(1)
Akira Matsuda
  • 1,854
  • 14
  • 9
  • If i do Dorm.find(1).photos.page(1) it does work. So it must be something with params[:id] but i dont know why that wouldnt work. – Rymo4 Jul 01 '11 at 08:13
  • scratch that, its not params[:id]. If I just find(1) instead, i get the same error. – Rymo4 Jul 01 '11 at 08:16
  • now i restarted my server and it works... i have no idea why because i had already restarted it. strange, but closed nonetheless. thanks. ill give you an accept even if it kinda fixed itself. – Rymo4 Jul 01 '11 at 08:18
-1
  1. is gem 'kaminari' in your Gemfile ?
  2. run bundler after changing your Gemfile
moc
  • 184
  • 3