module ActionView::Helpers::UrlHelper

def link_to(name = nil, options = nil, html_options = nil, &block)


# => Visit Other Site
link_to "Visit Other Site", "http://www.rubyonrails.org/", data: { confirm: "Are you sure?" }

# => Remove Profile
link_to "Remove Profile", profile_path(@profile), method: :delete

===== Rails UJS Examples

name for a disabled version of the link.
* :disable_with - Value of this parameter will be used as the
link is processed normally, otherwise no action is taken.
resulting text would be question?). If the user accepts, the
to prompt with the question specified (in this case, the
* confirm: "question?" - This will allow @rails/ujs

@rails/ujs also integrated with the following +:data+ options:

the link.
to make an Ajax request to the URL in question instead of following
* remote: true - This will allow @rails/ujs
the request object's methods for post?, delete?, patch?, or put?.
POST behavior, you should check for it in your controller's action by using
disabled clicking the link will have no effect. If you are relying on the
to using GET. If href: '#' is used and the user has JavaScript
Note that if the user has JavaScript disabled, the request will fall back
while spidering your site). Supported verbs are :post, :delete, :patch, and :put.
in dangerous actions like deleting a record (which search bots can follow
the HTTP verb specified. Useful for having links perform a POST operation
create an HTML form and immediately submit the form for processing using
* method: symbol of HTTP verb - This modifier will dynamically

this library is no longer on by default. This library integrated with the following options:
Prior to Rails 7, Rails shipped with a JavaScript library called @rails/ujs on by default. Following Rails 7,

==== Deprecated: Rails UJS Attributes

# => External link
link_to "External link", "http://www.rubyonrails.org/", target: "_blank", rel: "nofollow"

You can set any link attributes such as target, rel, type:

# => Nonsense search
link_to "Nonsense search", searches_path(foo: "bar", baz: "quux")

# => Ruby on Rails search
link_to "Ruby on Rails search", controller: "searches", query: "ruby on rails"

# => Comment wall
link_to "Comment wall", profile_path(@profile, anchor: "wall")

+link_to+ can also produce links with anchors or query strings:

# => WRONG!
link_to "WRONG!", controller: "articles", id: "news", class: "article"

Leaving the hash off gives the wrong link:

# => Articles
link_to "Articles", { controller: "articles" }, id: "news", class: "article"

Be careful when using the older argument style, as an extra literal hash is needed:

# => Articles
link_to "Articles", articles_path, id: "news", class: "article"

Classes and ids for CSS are easy to produce:


David -- Check it out!
# =>
<% end %>
<%= @profile.name %> -- Check it out!
<%= link_to(@profile) do %>

You can use a block as well if your link target is hard to fit into the name parameter. ERB example:

# =>
Eileen
link_to @profile

+to_s+ method returning a default value or a model instance attribute
More concise yet, when +name+ is an Active Record model that defines a

# => http://www.example.com
link_to nil, "http://example.com"

When name is +nil+ the href is presented instead

# => Profiles
link_to "Profiles", controller: "profiles"

is better than

# => Profiles
link_to "Profiles", profiles_path

Similarly,

# => Profile
link_to "Profile", controller: "profiles", action: "show", id: @profile

in place of the older more verbose, non-resource-oriented

# => Profile
link_to "Profile", @profile

or the even pithier

# => Profile
link_to "Profile", profile_path(@profile)

your application on resources and use
and newer RESTful routes. Current Rails style favors RESTful routes whenever possible, so base
Because it relies on +url_for+, +link_to+ supports both older-style controller/action/id arguments

==== Examples

* :data - This option can be used to add custom data attributes.
==== Options

link_to(active_record_model)

end
# name
link_to(url, html_options = {}) do

end
# name
link_to(options = {}, html_options = {}) do

# url_options, except :method, is passed to url_for
link_to(body, url_options = {}, html_options = {})

# posts_path
# url is a String; you can use URL helpers like
link_to(body, url, html_options = {})

==== Signatures

the value of the link itself will become the name.
will be used in place of a referrer if none exists). If +nil+ is passed as the name
of an options hash will generate a link to the referrer (a JavaScript back link
value of the \String as the href for the link. Using a :back \Symbol instead
pass a \String instead of an options hash, which generates an anchor element that uses the
See the valid options in the documentation for +url_for+. It's also possible to
Creates an anchor element of the given +name+ using a URL created by the set of +options+.
def link_to(name = nil, options = nil, html_options = nil, &block)
  html_options, options, name = options, name, block if block_given?
  options ||= {}
  html_options = convert_options_to_data_attributes(options, html_options)
  url = url_target(name, options)
  html_options["href"] ||= url
  content_tag("a", name || url, html_options, &block)
end