I found couple of similar cases but nothing to fix my problem...
I am using the gem Kaminari to paginate my app.
Since I added it, researches are failing and retrun this error undefined method total_pages' for #<Tuto::ActiveRecord_Relation:0x007fc3b2473d80>
I have a private method in my tutos controller to filter my tutos
def filter_tutos
return if params[:query].blank?
@tutos = Tuto.search(params[:query][:keyword]).includes(:user, :category) if params[:query][:keyword].present?
@tutos = Tuto.joins(:user).where('users.nickname LIKE ?', params[:query][:user]) if params[:query][:user].present?
@tutos = Tuto.joins(:category).where('categories.name LIKE ?', params[:query][:category]) if params[:query][:category].present?
end
index method in tutos controller :
def index
filter_tutos if params[:query].present?
@tutos ||= Tuto.all.page params[:page]
end
in my view I have:
.pagination
= paginate @tutos
I added paginates_per 5
in tuto model
Try this. Pagination is not called on @tutos
. If it is blank then all Tuto objects are paginated but not otherwise.
def index
filter_tutos if params[:query].present?
@tutos = @tutos.count > 0 ? @tutos : Tuto.all
@tutos = @tutos.page params[:page]
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.