سؤال

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.

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

Have you generated the partials that kaminari uses?

See the section titled "Customizing the pagination helper" here:

https://github.com/amatsuda/kaminari

Oncey ou do that, you can edit the _paginator.html.erb file (or other kaminari partials if you need to) in order to get the pagination functionality you're looking for. These partials allow you to use local variables, like "current_page", "num_pages" and a few more. Sounds like that's what you're looking for.

Here's what those partials look like, if you want to see them before running the generator:

https://github.com/amatsuda/kaminari/tree/master/app/views/kaminari

Hope that points you in the right direction.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top