Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In pagy gem in rails, how do you hide pagination when unneeded?

The pagination works well when it's needed. But even when it's not needed -- for example, when # set for pagination is 100 and the list is less than 100 --, the pagination shows like this:

‹ Prev 1 Next ›

How can I eliminate this?

My controller:

    @pagy, @users = pagy(User.all, items:100, link_extra: 'class="" style="color:#222222; margin-left:3px;"')

My view:

    <%== pagy_nav(@pagy) %>

Otherwise followed the documentation

like image 870
superbot Avatar asked Jan 12 '20 00:01

superbot


People also ask

How to install Pagy gem for pagination on Ruby on rails?

This minipost will guide you through all the required steps in order to successfully install pagy gem for pagination on a Ruby on Rails application using a custom HTML template. Start by adding the pagy gem to your application Gemfile [ appname/Gemfile] by: and perform bundle install inside directory to install the pagy gem:

What is Pagy on rails?

If you're new to Rails, you'll be looking for a pagination gem pretty soon. Pagy is a new pagination library for Ruby on Rails. It was developed with performance in mind, without disregarding being easy to use on a new or existing Ruby on Rails application.

How to paginate index pages in Ruby on rails?

If you've worked with Ruby on Rails in the past, then you probably used will_paginate or Kaminari to paginate the index pages of your application. If you're new to Rails, you'll be looking for a pagination gem pretty soon. Pagy is a new pagination library for Ruby on Rails.

What is the use of pagination in rails?

For that we use pagination that allow us to divide the rows on several pages and order them based on date, name or other field. On Rails applications one of the most common used gems is will_paginate.


1 Answers

The solution was to add this line:

<%== pagy_nav(@pagy) if @pagy.pages > 1 %>

Because unlike will_paginate or other pagination gems, pagy does not hide the link automatically.

like image 79
superbot Avatar answered Oct 29 '22 05:10

superbot