In Rails 3, when utilizing the method attribute of a link_to, my custom rel value is being overwritten.
# my code:
link_to 'Add to Favorites',
profile_favorites_path(profile),
:method => :post,
:class => 'button',
:rel => 'favorite'
# expected result:
<a href="/profiles/1/favorites" class="button" data-method="post" rel="favorite nofollow">Add to Favorites</a>
# actual result:
<a href="/profiles/1/favorites" class="button" data-method="post" rel="nofollow">Add to Favorites</a>
Is this a Rails bug / unexpected feature? How can I make use of the built-in method functionality while also supplying a custom rel value?
Seems you can only specify the
relattribute if themethodis set to get.Inside
action_view/helpers/url_helper.rbadd_method_to_attributes!you can see the logic rails is currently using for this:This actually makes sense, you wouldn’t want to have bots/spiders posting when crawling links.