8
我知道我可以通过:rel => "nofollow"
到link_to
,但是有没有办法在默认情况下进行设置,因此我无需在每个link_to
标记中进行更改?如何在Rails中自动设置所有链接到nofollow
我知道我可以通过:rel => "nofollow"
到link_to
,但是有没有办法在默认情况下进行设置,因此我无需在每个link_to
标记中进行更改?如何在Rails中自动设置所有链接到nofollow
在您的应用帮手中,您可以覆盖link_to
方法并用您自己的方法替换。
def link_to(name, options = {}, html_options = {})
html_options.merge!(:rel => :nofollow)
super(name, options, html_options)
end
您可以为旧的link_to
创建别名,然后覆盖它,以便使用额外参数调用旧别名。这样,您不必更改代码中现有的所有link_to
。
如果你不想已经覆盖你的链接上的任何'rel'值,请尝试使用''merge_nicely改为:https://gist.github.com/joshuapinter/78a5545d713ab9d55883 – 2014-09-21 05:01:58