0

I am working on rails 4 and this are my steps:-

  1. gem kaminari --in gemfile
  2. bundle install
  3. @vendors = Vendor.order(:name).page params[:page] in vendor_controller.rb) also tried @vendors=Vendor.order("name").page(params[:page]).per(5)
  4. <% = paginate @vendors %> in index.html.erb

Error:-

undefined method `page' for #<ActiveRecord::Relation::ActiveRecord_Relation_Vendor:0x16bec10>

I have also tried in console

Vendor.count                 
a = Vendor.limit(5).count     
b = a.page(1).per(20).size

Error:- NOmethoderror undefined method 'page'

question:- Where i am going wrong .?

Thanks

Dhaulagiri
  • 3,281
  • 24
  • 26
SNEH PANDYA
  • 797
  • 7
  • 22

2 Answers2

1

Try calling the page method directly from the ActiveRecord class. You're calling it after order, which returns an ActiveRecord::Relation object.

@vendors = Vendor.page(params[:page]).order(:name)
S. A.
  • 3,714
  • 2
  • 20
  • 31
0

I think this one may solve your problem:

 vendor.except(:limit, :offset)

In model use:

 paginates_per 5
ivcubr
  • 1,988
  • 9
  • 20
  • 28
Shubham45
  • 1
  • 1