ActionView::Helpers::UrlHelper
def current_page?(options = nil, check_parameters: false, method: :get, **options_as_kwargs)

Description

Returns true if the given URL matches the URL of the current request, otherwise false.

This site renders with GET /articles?page=2, shown above the ERB, as the current request.

Arguments

Changing a value updates the ERB and HTML.

Converted to a URL with url_for, then compared with the current request:
  • A URL without ?: compared with the current request without its query string (?page=2).
  • A URL with ?: compared including the query string.
  • A URL starting with https:// or similar: the current request's protocol and host (such as https://example.com) are prepended to its path before comparing.
A trailing / is removed from both. A hash may also hold check_parameters and method, used like the keyword arguments. If omitted, any other keyword arguments (such as controller: "articles") are collected into a hash and used instead. With no keyword arguments either, url_for gets {}, which gives the current request's path, so it returns true.
= false
true
true compares the current request's query string even for a URL without ? ("/articles" differs from /articles?page=2, so it returns false).
= :get
If the current request's HTTP method differs from this, returns false without comparing URLs (or, for an array, if it matches none of its values). Pass a lowercase symbol; a string ("get") or :GET always returns false. :get also matches a HEAD request, including inside an array. The current request is a GET, so :post returns false.

ERB

Changes from the previous output: Added Removed Changed

Current request
GET /articles?page=2

          

HTML