Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paginate two or more collections in one action #20

Closed
cseelus opened this issue May 28, 2018 · 6 comments
Closed

Paginate two or more collections in one action #20

cseelus opened this issue May 28, 2018 · 6 comments

Comments

@cseelus
Copy link
Contributor

cseelus commented May 28, 2018

If I understand it correctly, currently the only way to rename the page param, is to redefine pagy_get_params.

Will paginate for example allows to do something like this:

paginate @my_collection, param_name: 'custom_param_name'

Which in turn easily enables to have more than one collection paginated per action.

@ddnexus, would something like this be a feature that you are willing to add (yourself or via a PR) or is this outside the scope of Pagy?

@ddnexus
Copy link
Owner

ddnexus commented May 28, 2018

Nope. You can do it right now by doing:

@pagy, @records = pagy(@mycollection, page: param[:custom_param_name])

@ddnexus
Copy link
Owner

ddnexus commented May 28, 2018

and BTW... pagy_get_params is the way to massage the params. (see Customizing the params).

The proper way to change the param name (but for all instances) would be overriding pagy_get_vars, which would work as a default for all the pagy calls, but... just pass a variable to the pagy method and it will override the default.

@cseelus
Copy link
Contributor Author

cseelus commented May 28, 2018

Yes, I also thought/wrote pagy_get_params was the way to go to modify the page links, but to paginate two collections in one action/on one page, you would need to define two helpers that both would redefine pagy_get_params?

@ddnexus
Copy link
Owner

ddnexus commented May 28, 2018

but to paginate two collections in one action/on one page, you would need to define two helpers that both would redefine pagy_get_params?

Absolutely not:

@pagy, @records = pagy(@mycollection)               # uses params[:page]
@custom_pagy1, @custom_records = pagy(@mycollection1, page: param[:custom_param_name1])
@custom_pagy2, @custom_records2 = pagy(@mycollection2, page: param[:custom_param_name2])

@cseelus
Copy link
Contributor Author

cseelus commented May 28, 2018

<%= pagy_nav @custom_pagy1 %> will generate links like <a href="/collection?page=2"> though, using page as the page param instead of custom_param_name1.

@ddnexus
Copy link
Owner

ddnexus commented May 28, 2018

True! And wrong! I have to fix that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants