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
How to 'Join' an Array Adding to the Beginning of the Resulting String the First Character to Join
How to Update a Model's Attribute with a Virtual Attribute
"Bad Ecpoint" Ssl Error on Fresh Rvm Ruby 1.9.3 Install on Osx Mountain Lion
How to Push a Custom Gem to Heroku Master
Rails Adding Multiple Objects to an Empty Array
How to Dynamically Create Instance Methods at Runtime
Ruby Getting Deeply Nested JSON API Data
Why Do We Need Nginx with Thin on Production Setup
Assign to an Array and Replace Emerged Nil Values
Ternary Expression with "Defined" Returns "Expression" Instead of Value
How to Split a String of Repeated Characters with Uneven Amounts? Ruby
Ruby Gsub Problem When Using Backreference and Hashes
Iterate JSON with Ruby and Get a Key,Value in an Array
Where Are Catch and Throw Useful in Ruby