Kaminari Undefined Method 'Total_Pages'

kaminari undefined method `total_pages'

You need to paginate both queries. I recommend something like:

def index
if params[:tag]
@lists = List.tagged_with(params[:tag])
else
@lists = List.all
end
@lists = @lists.order(created_at: :desc).paginate(page:params[:page], per_page: 3 )
end

Otherwise @lists will not be a pagination object when params[:tag] is nil.

Rails and kaminari -- undefined method total_pages

You're using an Array so you should use Kaminari.paginate_array method:

https://github.com/kaminari/kaminari#paginating-a-generic-array-object

Kaminari : undefined method total_pages

try this, I hope this will work.

def search
@location = params[:search]
@distance = params[:km]
@renters = Renter.near(@location, 30000).order("distance")

if @renters.empty?
@renters = Renter.all
search_map(@renters)
else
search_map(@renters)
end
@renters = @renters.page(params[:page])
end

undefined method `total_pages' for #Tuto::ActiveRecord_Relation:0x007fc3b2473d80

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

Rails, undefined method `total_pages' #PG::Result:0x007f3ede39dae0

I done with this. get total count from query.

query << " select count(*) OVER() AS total_count,
pp.id,
ud.last_name || ' ' || ud.first_name as full_name,
pp.image_file_name,
pp.gender_type ,
pp.no_of_view_for_last_30_days ,
pp.no_of_likes ,
pp.no_of_comments,
pp.tenpo_name_display,
pp.online_open ,
pp.online_comment from product pp
inner join user_details ud on pp.user_id = ud.user_id
inner join user_labels ul on ul.user_id = ud.user_id
where pp.flag = false and end_dt is null"

offset = params[:page].present? ? (params[:page].to_i - 1) * 30 : 0
@posts = ActiveRecord::Base.connection.execute(query + 'limit 30 offset ' + offset.to_s )
posts_count = !@posts.nil? ? @posts.first["total_count"] : 0
@post_count = @posts.to_a.paginate(page: params[:page], per_page: 30, total_entries: posts_count)

passing param as total_entries to pagination. It's work.



Related Topics



Leave a reply



Submit