Kaminari undefined method `total_pages'

I am using kaminari and error.

Gemfile:

# gem 'will_paginate', '~> 3.0.6' # gem 'will_paginate-bootstrap' gem 'kaminari' 

lists_controller.rb

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

I am also a user .page params[:page].per(2) follows .order(created_at: :desc) but does not work

Views / Lists / index.html.erb

 <%= paginate @lists %> 

mistake here

 undefined method `total_pages' for #<List::ActiveRecord_Relation:0x007fa2303e3fa8> Extracted source (around line #26): </div> </div> <%= paginate @lists %> <div class="container"> <div class="row"> <div class="col-md-8"> 

I do not know how to do this, I copy railscasts about kaminari, and the video is Ok, I have an error. thanks, help me.

+5
source share
2 answers

You need to separate both requests. 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 if params[:tag] is zero.

+5
source

Try pagination:

  List.tagged_with(params[:tag]).order(created_at: :desc).page(params[:page]).per(3) 
0
source

Source: https://habr.com/ru/post/1245273/


All Articles