Skip to content

Commit ab23ee6

Browse files
committed
Merge pull request #41206 from intrip/41198-fix-current-page-kwargs
Fix current_page? with kwargs on ruby3
1 parent 1514745 commit ab23ee6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

actionview/lib/action_view/helpers/url_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def mail_to(email_address, name = nil, html_options = {}, &block)
539539
#
540540
# We can also pass in the symbol arguments instead of strings.
541541
#
542-
def current_page?(options, check_parameters: false)
542+
def current_page?(options = nil, check_parameters: false, **options_as_kwargs)
543543
unless request
544544
raise "You cannot use helpers that need to determine the current " \
545545
"page unless your view context provides a Request object " \
@@ -548,6 +548,7 @@ def current_page?(options, check_parameters: false)
548548

549549
return false unless request.get? || request.head?
550550

551+
options ||= options_as_kwargs
551552
check_parameters ||= options.is_a?(Hash) && options.delete(:check_parameters)
552553
url_string = URI::DEFAULT_PARSER.unescape(url_for(options)).force_encoding(Encoding::BINARY)
553554

actionview/test/template/url_helper_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,12 @@ def test_current_page_considering_params_when_options_does_not_respond_to_to_has
564564
assert_not current_page?(:back, check_parameters: false)
565565
end
566566

567+
def test_current_page_when_options_given_as_keyword_arguments
568+
@request = request_for_url("/")
569+
570+
assert current_page?(**url_hash)
571+
end
572+
567573
def test_current_page_with_params_that_match
568574
@request = request_for_url("/?order=desc&page=1")
569575

0 commit comments

Comments
 (0)