如何在Rails中自动将所有链接设置为nofollow

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

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

 def link_to(name, options = {}, html_options = {}) html_options.merge!(:rel => :nofollow) super(name, options, html_options) end 

您可以为旧link_to创建别名,然后覆盖它,以便使用extra参数调用旧别名。 这样,您就不必更改代码中的所有现有link_to

Interesting Posts