Im using the ransack gem which performs queries and shows relevant posts. Now I'm trying to implement the kaminari gem to show 12 posts per page.
here is my controller:
def index
@search = Post.search(params[:q])
@post = @search.result(distinct: true)
@post = Post.order('created_at DESC').page(params[:page]).per(12)
end
the problem I have is when i click on the search button, it does not work, the posts same the same, nothing gets updated.
Don't run the kaminari paging on Post
... that just ignores the ransack results and creates a new collection. Run paging on the @post
collection.
def index
@search = Post.search(params[:q])
@post = @search.result(distinct: true)
@post = @post.order('created_at DESC').page(params[:page]).per(12)
end
So i figured out the answer, rather than use the kaminari gem
, i switched over to will_paginate gem
and changed my controllers index method to:
@search = Post.search(params[:q])
@posts = @search.result(distinct: true).paginate(page: params[:page], per_page: params[:per_page])
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.