ruby-on-railsruby-on-rails-3kaminari

Kaminari pagination, how to get the number of the current page?


I am using Kaminari to paginate some results from a db query.

I would like to apply specific styling to the first page of the results. The operation is very easy once I know on what page the user is, but I can't find a way to detect the current page.


Solution

  • If you want to check for first page you can do it like this:

     if object.first_page?
        #your logic here
     end
    

    If you find the specific page you can do something like this:

    current_page_no = object.current_page

    For more info refer: http://www.rubydoc.info/github/amatsuda/kaminari/master/Kaminari/PageScopeMethods