Goal: By default I want all links on my website to have attached
rel="nofollow" attribute unless I am linking to few specific domains (in which case I want these links to have
I tried to come up with custom helper
link_to to achieve this goal but yet it still doesn’t work.
def link_to(*args, &block) options = args.extract_options! name = block_given? ? '' : args.shift href = args.first if href =~ %r[^https?://] # skip local links host = href.split('/') unless host =~ /DOMAINX\.com$/ || /DOMAINY\.com$/ || /DOMAINZ\.com$/ || /DOMAINV\.com$/ options.reverse_merge!(:target => '_blank', :rel => 'nofollow') end end super(*[name, href, options.empty? ? nil : options].compact, &block) end
DOMAINX, DOMAINY, DOMAINZ, DOMAINV etc. are these domains I want them to be
Can anyone help me adjust this code to make it happen?