Rails Pagination with Kaminari with has_many :through Relationship -
i have 3 relevant models. user has_many :photos , belongs_to :dorm, dorm has_many :users , has_many :photos, :through => :users, , photo class belongs_to :users , belongs_to :dorm.
i want paginate photos in dorm kaminari. have in gemfile , ran bundle command.
in dorms_controller:
@dorm=dorm.find(params[:id]) @photos=@dorm.photos.page(params[:page]).per(3) and in dorm show view (actually in partial, _index.html.erm rendered in show view):
<%= paginate @photos %> this gives me error: undefined method 'page' #<class:0x107483d68>.
i know why doesn't work (shouldn't called on class), don't know how make work...
hrm, strange. should work. made vanilla app action shown above , following models, couldn't reproduce 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 root cause in app code. so, track down problem bit more? begin with, following code work in rails console?
@dorm.photos.page(1)
Comments
Post a Comment