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

时间:2010-08-20 16:54:54

标签: ruby-on-rails ruby nofollow

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

2 个答案:

答案 0 :(得分:20)

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

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

答案 1 :(得分:2)

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