How to automatically set all links to nofollow in Rails
Asked Answered
R

2

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?

Repro answered 20/8, 2010 at 16:54 Comment(0)
R
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
Rockhampton answered 20/8, 2010 at 17:6 Comment(1)
In case you don't want to overwrite any rel values already on your link, try using merge_nicely! instead: gist.github.com/joshuapinter/78a5545d713ab9d55883Rooney
P
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.

Pingpingpong answered 20/8, 2010 at 17:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.