如何在Rails中自动将所有链接设置为nofollow [英] How to automatically set all links to nofollow in Rails

查看:32
本文介绍了如何在Rails中自动将所有链接设置为nofollow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以通过 :rel =>nofollow"link_to 但有没有办法在默认情况下设置它,这样我就不必在每个 link_to 标签中进行更改?

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?

推荐答案

在您的应用程序助手中,您可以覆盖 link_to 方法并替换为您自己的方法.

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

这篇关于如何在Rails中自动将所有链接设置为nofollow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆