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