mercredi 2 septembre 2020

Rails, Pagination offset not working, after clicking on '2' number(pagination) or other's page's

I am trying to pass offset in pagination.

  params[:page] = 1 if params[:page].nil?
  @pagination_count = (params[:pagination_count].present?) ? params[:pagination_count] : 50
  offset = ''
  if params[:page] != 1 
    offset = "limit 50 offset #{(params[:page].to_i - 1) * 50}"
  else
    offset = "limit 50"
  end
 posts_count =  ActiveRecord::Base.connection.execute(query + ' where ' + query2 + query1).count 
 @posts =  ActiveRecord::Base.connection.execute(query + ' where ' + query2 + query1 + offset).to_a.paginate(page: params[:page], per_page: 50, total_entries: posts_count) 

But, it's not working on click 2 page(pagination number), 2nd page is viewed but, data didn't get. on 1st page data displayed.

Aucun commentaire:

Enregistrer un commentaire