Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

will_paginate -error-undefined method `total_pages'

I am using will_paginate "2.3.15" for my rails app

in my units_controller.rb

def index
    @units = Unit.paginate(:all ,:page => params[:page], :order => 'created_at DESC')
end

in my views(index)

        <%= will_paginate(@units)%>

but it gives error

undefined method `total_pages' for #<ActiveRecord::Relation:0xb523dc>

my rails version 3.0.0 and ruby version 1.8.7

plz help

like image 412
Harshal_m_joshi Avatar asked Jun 15 '11 10:06

Harshal_m_joshi


1 Answers

Why do you add the :all ? From the will_paginate wiki you should probably use :

@units = Unit.paginate(:page => params[:page], :order => 'created_at DESC')
like image 90
Adrien Coquio Avatar answered Oct 21 '22 15:10

Adrien Coquio