开发者

How to automatically set all links to nofollow in Rails

开发者 https://www.devze.com 2023-01-12 05:44 出处:网络
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? In your application helper you can

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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消