My controller fetches the collection
@slots = @license.slots.paginate(:page => params[:page]).reject {|s|
!s.visible }
and my .slim view does a:
==will_paginate @slots
I am getting:
undefined method `total_pages' for []:Array
What's wrong here?
## app.rb
helpers WillPaginate::Sinatra::Helpers
## boot.rb
Padrino.before_load do
require 'will_paginate/data_mapper' # or active_record/sequel
DataMapper.finalize
end
If it turns out you can't get around it, try adding:
require 'will_paginate/array'
Sorry, I'm not in a situation where I can test a better solution, but
that should allow you to paginate an array.
Adam
--
----=^.^=---
> Can you confirm which version of the Gem you are using, and that you
> are manually adding the sinatra helper?
I am using 3.0.2 of the gem and this is my app.rb
class Admin < Padrino::Application
register Padrino::Mailer
register Padrino::Helpers
register Padrino::Rendering
register Padrino::Admin::AccessControl
helpers WillPaginate::Sinatra::Helpers
...
end
> Also, which ORM are you using?
I am using DataMapper.
> ## boot.rb
> Padrino.before_load do
> require 'will_paginate/data_mapper' # or active_record/sequel
> DataMapper.finalize
> end
mine looks like this, cause I specified required=>nil in the Gemfile.
But it makes no difference, even when bundler autoloads it.
Padrino.before_load do
require 'will_paginate'
require 'will_paginate/data_mapper'
end
I am not calling DataMapper.finalize, is it required? I am using
migrations instead of auto_upgrade.
> If it turns out you can't get around it, try adding:
>
> require 'will_paginate/array'
I added that in my Padrino_load to no avail.
>
> Sorry, I'm not in a situation where I can test a better solution, but
> that should allow you to paginate an array.
I hope I can find a solution.
It works in the irb though:
irb(main):068:0> require "will_paginate/array"
=> true
irb(main):069:0> [].paginate
=> []
irb(main):070:0> [1,2,3,4,5].paginate
=> [1, 2, 3, 4, 5]
irb(main):071:0> [1,2,3,4,5].paginate(:per_page=>2)
=> [1, 2]
irb(main):072:0> [1,2,3,4,5].paginate(:per_page=>2).
Display all 4407 possibilities? (y or n)
irb(main):072:0> a = [1,2,3,4,5].paginate(:per_page=>2)
=> [1, 2]
irb(main):073:0> a.total_pages
=> 3
Phil