Access to collection object on current page w will_paginate

Specifications: ruby ​​2.1.5p273, Rails 4.2.3.

I use the will_paginate pearl to break my model down the page. Is it possible to have access to model instances that are printed on the current page?

In the project controller:

@paginate_projects = @projects.keys.paginate(:page => params[:page], :per_page => 7)

Using Pry, I can get:

$ @paginate_projects.current_page => 2

I want to be able to do something like:

$ @paginate_projects.current_page.projects => [Project #8, Project #9, Project #10, Project #11, Project #12, Project #13, Project #14]

Thanks in advance for any help. I looked at this: http://www.rubydoc.info/github/mislav/will_paginate/WillPaginate/Collection

+4
source share
2 answers

, @projects.keys ( , ), @projects (, , Project) .

#paginate ActiveRecord, .

, :

@projects = Project.some_scope_or_query
@paginate_projects = @projects.paginate(page: params[:page], per_page: 7)

/ @paginate_projects .

, . - :

@projects = Project.some_scope_or_query
                     .paginate(page: params[:page],
                               per_page: 7)

, @projects .

0

will_paginate gem, , @paginate_projects ActiveRecord .

:

, , . WillPaginate:: Collection . .

-2

Source: https://habr.com/ru/post/1608729/


All Articles