librelist archives

« back to archive

will_paginate revisited

will_paginate revisited

From:
Kevin Zurawel
Date:
2012-01-04 @ 14:23
Hi,

I've been trying to follow along with the pagination discussion from here:
http://librelist.com/browser//nesta/2011/12/11/pagination/
But I'm having the same problems. Here are the things I've tried:

1. Added will_paginate to my Gemfile, ran bundle install.

2. Added require 'will_paginate' and require 'will_paginate/array' to my 
theme's app.rb.

3. Put the following code in my view (articles/index.haml, a category page):
  - posts = @page.articles
  - posts.paginate(:page => params[:page] ? params[:page] : 1, :per_page => 6)
  - posts.each do |post|
    %article
      %div
        %h3
          %a(href="#{post.permalink}")= post.title
        = post.summary
        %a(href="#{post.permalink}")= post.read_more

I don't get any errors about .paginate, but it also doesn't do anything 
(it shows all 30-ish articles, not just 6).
If I add:
= will_paginate @posts
I get an error: no method 'will_paginate' for #<Nesta::App…

4. I tried adding:
- require 'will_paginate'
- require 'will_paginate/array'
to the view before calling .paginate; same results.

5. I made a new route in my theme's app.rb and changed my view to use @posts:
get '/articles' do
  set_common_variables
  @page = Nesta::Page.find_by_path('articles')
  @posts = @page.articles
  @posts.paginate(:page => params[:page], :per_page => 6)
  cache haml(:page, :format => :xhtml)
end
(I don't have a separate page for it, just wanted to use the default 
page.haml template)
This does the same thing as #3 - no complaints about .paginate, but no 
effect either; error if I add will_paginate.

I'm not really sure what else to try. It seems like Nesta isn't getting 
the will_paginate helper, even though requiring 'will_paginate' should 
pull in WillPaginate::ViewHelpers::Sinatra. I've seen some mention of 
"registering" the view helper, but when I try that in my theme's app.rb I 
get an error: unregistered constant WillPaginate::Sinatra.

Any help would be greatly appreciated!
Kevin Zurawel
http://arborwebsolutions.com (currently WordPress)
http://testbed.arborwebsolutions.com (Nesta-powered redesign)

Re: [nesta] will_paginate revisited

From:
Graham Ashton
Date:
2012-01-06 @ 08:09
On 4 Jan 2012, at 14:23, Kevin Zurawel <kzurawel@gmail.com> wrote:

> I've been trying to follow along with the pagination discussion from here:
> http://librelist.com/browser//nesta/2011/12/11/pagination/
> But I'm having the same problems. Here are the things I've tried:

That's a good list, but following the same steps doesn't sound like a 
quick thing for anybody to investigate. Can I get access to your code?

I've never tried will_paginate in Sinatra, but I'm pretty handy with the debugger…

Re: [nesta] will_paginate revisited

From:
Kevin Zurawel
Date:
2012-01-06 @ 14:17
Hi Graham,

Here's a link to my code on Github:

https://github.com/kzurawel/aws2012

Thanks for your help. I'll be sure to write up some documentation on how I
got this all working.


On Jan 6, 2012, at 3:09 AM, Graham Ashton wrote:

> On 4 Jan 2012, at 14:23, Kevin Zurawel <kzurawel@gmail.com> wrote:
> 
>> I've been trying to follow along with the pagination discussion from here:
>> http://librelist.com/browser//nesta/2011/12/11/pagination/
>> But I'm having the same problems. Here are the things I've tried:
> 
> That's a good list, but following the same steps doesn't sound like a 
quick thing for anybody to investigate. Can I get access to your code?
> 
> I've never tried will_paginate in Sinatra, but I'm pretty handy with the
debugger…

Re: [nesta] will_paginate revisited

From:
Graham Ashton
Date:
2012-01-06 @ 16:16
On 6 Jan 2012, at 18:17, Kevin Zurawel wrote:

> Here's a link to my code on Github:
> 
> https://github.com/kzurawel/aws2012

Here's a pull request with a comment explaining what was wrong (it was 
vanilla will_paginate in Sinatra, nothing Nesta specific was wrong with 
it):

https://github.com/kzurawel/aws2012/pull/1

The docs on how to setup will_paginate in Sinatra are pretty ropey, but 
the approach to loading the helpers does get a mention here:

https://github.com/mislav/will_paginate/wiki/installation

> I'll be sure to write up some documentation on how I got this all working.

Cracking, thanks.

Re: [nesta] will_paginate revisited

From:
Kevin Zurawel
Date:
2012-01-06 @ 16:26
Well that was simple. Thanks!

On Jan 6, 2012, at 11:16 AM, Graham Ashton wrote:

> On 6 Jan 2012, at 18:17, Kevin Zurawel wrote:
> 
>> Here's a link to my code on Github:
>> 
>> https://github.com/kzurawel/aws2012
> 
> Here's a pull request with a comment explaining what was wrong (it was 
vanilla will_paginate in Sinatra, nothing Nesta specific was wrong with 
it):
> 
> https://github.com/kzurawel/aws2012/pull/1
> 
> The docs on how to setup will_paginate in Sinatra are pretty ropey, but 
the approach to loading the helpers does get a mention here:
> 
> https://github.com/mislav/will_paginate/wiki/installation
> 
>> I'll be sure to write up some documentation on how I got this all working.
> 
> Cracking, thanks.