Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


link_to doesn't allow rel attribute when also specifying method #1796

merged 2 commits into from

3 participants


When using link_to and specifying a relation and a method like:

link_to('Somesuch', '/path', :method => :post, :rel => 'junk')

It generates:

    <a href="/path" data-method="post" rel="nofollow">Somesuch</a>

But this method should also allow me to specify my own relation like:

    <a href="/path" data-method="post" rel="junk nofollow">Somesuch</a>

Just commenting here so I can track this pull request for closure on the original StackOverflow question I posted over there. :)


@jdeseno can you add a test case please?


@jdeseno: You rock! Would love to see this pulled into master. As defined by the W3, the rel attribute on link tags should allow such values:

This attribute describes the relationship from the current document to the anchor specified by the href attribute. The value of this attribute is a space-separated list of link types.

@spastorino spastorino merged commit 7f6eed0 into from
@jake3030 jake3030 referenced this pull request from a commit in jake3030/rails
@levinalex levinalex Make TimeWithZone#to_formatted_s an alias to TimeWithZone#to_s [#1796

Is there a way to get this reopened? It looks like this code never made it into the Rails 3.1 branch. Shouldn't it be included there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
4 actionpack/lib/action_view/helpers/url_helper.rb
@@ -619,7 +619,9 @@ def link_to_remote_options?(options)
def add_method_to_attributes!(html_options, method)
- html_options["rel"] = "nofollow" if method.to_s.downcase != "get"
+ if method && method.to_s.downcase != "get"
+ html_options["rel"] = "#{html_options["rel"].to_s} nofollow".split(" ").uniq.join(" ")
+ end
html_options["data-method"] = method
7 actionpack/test/template/url_helper_test.rb
@@ -245,6 +245,13 @@ def test_link_tag_using_delete_javascript_and_href
+ def test_link_tag_using_post_javascript_and_rel
+ assert_dom_equal(
+ "<a href='' data-method=\"post\" rel=\"example nofollow\">Hello</a>",
+ link_to("Hello", "", :method => :post, :rel => 'example')
+ )
+ end
def test_link_tag_using_post_javascript_and_confirm
"<a href=\"\" data-method=\"post\" rel=\"nofollow\" data-confirm=\"Are you serious?\">Hello</a>",
Something went wrong with that request. Please try again.