문제

I'm trying to do pagination using the will_paginate gem:

@books = Book.joins(:ads).last(20).page(params[:page]).per_page(10)

But I'm getting this error: undefined method `page' for #<\Array:0x007fc3ef37d308> and I can't seem to figure out what's wrong. Pagination works like a charm in other actions.

Thanks! :)

도움이 되었습니까?

해결책

Don't use last as that will trigger the query execution. Use reverse_order and limit instead.

Book.joins(:ads).reverse_order.limit(20).page(params[:page]).per_page(10)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top