ActionView::Helpers::UrlHelper

link_to_unless_current

API docs (Rails 8.1.4.1) ↗
def link_to_unless_current(name, options = {}, html_options = {}, &block)

Description

Creates an <a> unless the given URL is the current page; on the current page, returns only the content, as a string.

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.

The content of the <a>, escaped. When no <a> is created, the escaped string is still returned. With nil, the content is the href value when an <a> is created, and an empty string is returned when not.
Passed to current_page? to decide whether this is the current page ("/articles" has no ?, so it matches the current request /articles?page=2). If it is not the current page, it is passed to url_for, as in link_to, and used as the href.
html_options= {}
Sets the data-method attribute. If it is not :get, also adds rel="nofollow"; if rel is also given, nofollow is appended to it. data-method is an HTML attribute read by Rails UJS; in apps without Rails UJS (the default since Rails 7), it does nothing.
Common options

Rails handles these options the same way in every helper. Options the HTML spec does not allow on the <a>, and ones this site considers rarely used, are not listed here.

Shared by all helpers

{active: true, hidden: false}
A hash gives the keys whose values are not false or nil, joined with spaces. An array gives its elements joined with spaces, after removing nil, false and empty strings (including whitespace-only strings).
{controller: "tags", tags_suggestions_value: ["ruby", "rails"]}
A hash adds data-* attributes, with _ in the keys converted to -. Array and hash values are converted to JSON strings.
{describedby: ["name_help", "name_error"], invalid: false}
Like :data, adds aria-* attributes. Array values are joined with spaces, leaving out nil and empty strings (nothing is added if none remain). For a hash value, the keys whose values are not false or nil are joined with spaces.
Any other options become HTML attributes of the <a>; those with a nil value are left out.
&block= nil
On the current page, the block's output is returned instead of name. The block receives name (and options and html_options if it takes two or more arguments). Ignored when it is not the current page.

ERB

Changes from the previous output: Added Removed Changed

Current request
GET /articles?page=2

          

HTML


          

Preview