Question

I'm using nestacms for a new website.

I'm trying to add pagination where i'm listing articles.

There's no documentation on the official website.

I've tried with following gems :

  • will_paginate
  • kaminary

But I don't get it.

Do somone knows how to add pagination on nestacms ?

Thanks.

Was it helpful?

Solution

Well, it is quite complicated. As far as you don't have write access to Nesta controllers and Nesta doesn't use any database, you cannot use pagination gems.

As quick-and-dirty solution I made some changes in /views/summaries.haml

- unless pages.empty?
  - per_page = 10
  - page = params[:page].nil? ? 1 : params[:page].to_i
  - start_page = (page - 1) * per_page
  - end_page = page * per_page - 1

  - all_pages = Nesta::Page.find_articles
  - pages = all_pages[start_page..end_page]
  %ol

...unchanged code here

        = haml :page_meta, :layout => false, :locals => { :page => page }

  -if page*per_page < all_pages.size
    %a.perv{href:"/?page=#{page+1}"} Previous page
  -if page > 1
    %a.next{href:"/?page=#{page-1}"} Next page

Then you could adjust your .prev and .next classes as you like with CSS

As very proper solution I would suggest to make a pull request to Nesta repository with any pagination gem support by default.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top