From 905a0238230c80d306332608ffb0cb3580cdcbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Serge=20H=C3=A4nni?= Date: Sat, 4 Dec 2021 18:41:13 +0100 Subject: [PATCH 1/2] Add documentation for proper usage of `format` parameter --- README.md | 6 ++++++ kaminari-core/test/helpers/action_view_extension_test.rb | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index e281af7..c1d752f 100644 --- a/README.md +++ b/README.md @@ -288,6 +288,12 @@ This option makes it easier to do things like A/B testing pagination templates/t This simply renders a link to the next page. This would be helpful for creating a Twitter-like pagination feature. +The helper methods support a `params` option to further specify the link. If `format` needs to be set, inlude it in the `params` hash. + +```erb +<%= link_to_next_page @items, 'Next Page', params: {controller: 'foo', action: 'bar', format: :turbo_stream} %> +``` + ### The `page_entries_info` Helper Method ```erb diff --git a/kaminari-core/test/helpers/action_view_extension_test.rb b/kaminari-core/test/helpers/action_view_extension_test.rb index 66328d2..b3e2c68 100644 --- a/kaminari-core/test/helpers/action_view_extension_test.rb +++ b/kaminari-core/test/helpers/action_view_extension_test.rb @@ -526,6 +526,11 @@ if defined?(::Rails::Railtie) && defined?(::ActionView) users = User.page(2).per(1) assert_nil view.path_to_next_page(users, params: {controller: 'users', action: 'index'}) end + + test 'format option' do + users = User.page(1).per(1) + assert_equal '/users.turbo_stream?page=2', view.path_to_next_page(users, params: {controller: 'users', action: 'index', format: :turbo_stream}) + end end sub_test_case '#path_to_prev_page' do From 49649084824bdff6de4559f3fb7d7173cbba31b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Serge=20H=C3=A4nni?= Date: Tue, 7 Dec 2021 12:08:12 +0100 Subject: [PATCH 2/2] Add `format` parameter to `paginate` example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c1d752f..bd3cc62 100644 --- a/README.md +++ b/README.md @@ -258,7 +258,7 @@ This would modify the query parameter name on each links. ### Extra Parameters (`:params`) for the Links ```erb -<%= paginate @users, params: {controller: 'foo', action: 'bar'} %> +<%= paginate @users, params: {controller: 'foo', action: 'bar', format: :turbo_stream} %> ``` This would modify each link's `url_option`. :`controller` and :`action` might be the keys in common.