8

I know I can pass :rel => "nofollow" to link_to but is there a way to set that by default so I don't have to make changes in each link_to tag?

Abel
  • 56,041
  • 24
  • 146
  • 247
deb
  • 12,326
  • 21
  • 67
  • 86

2 Answers2

19

In your application helper you can override the link_to method and replace with your own.

def link_to(name, options = {}, html_options = {})
  html_options.merge!(:rel => :nofollow)
  super(name, options, html_options)
end
Abel
  • 56,041
  • 24
  • 146
  • 247
Jesse Wolgamott
  • 40,197
  • 4
  • 83
  • 109
  • In case you don't want to overwrite any `rel` values already on your link, try using `merge_nicely!` instead: https://gist.github.com/joshuapinter/78a5545d713ab9d55883 – Joshua Pinter Sep 21 '14 at 05:01
2

You could create an alias to the old link_to then override it so it calls the old alias with the extra parameter. That way, you don't have to change all the existing link_to in your code.

Abel
  • 56,041
  • 24
  • 146
  • 247
Zaki
  • 1,101
  • 9
  • 7