diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index 6f163032ed..75c59cddab 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -541,7 +541,7 @@ def mail_to(email_address, name = nil, html_options = {}, &block) # # We can also pass in the symbol arguments instead of strings. # - def current_page?(options, check_parameters: false) + def current_page?(options = nil, check_parameters: false, **options_as_kwargs) unless request raise "You cannot use helpers that need to determine the current " \ "page unless your view context provides a Request object " \ @@ -550,6 +550,7 @@ def current_page?(options, check_parameters: false) return false unless request.get? || request.head? + options ||= options_as_kwargs check_parameters ||= options.is_a?(Hash) && options.delete(:check_parameters) url_string = URI::DEFAULT_PARSER.unescape(url_for(options)).force_encoding(Encoding::BINARY) diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index e7798e28fa..bd38a67724 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -582,6 +582,12 @@ def test_current_page_considering_params_when_options_does_not_respond_to_to_has assert_not current_page?(:back, check_parameters: false) end + def test_current_page_when_options_given_as_keyword_arguments + @request = request_for_url("/") + + assert current_page?(**url_hash) + end + def test_current_page_with_params_that_match @request = request_for_url("/?order=desc&page=1")