It’s really very simple, but this one took me a while to figure out, so I thought I’d post it in case it helps someone else.

If you want to add a rel='nofollow' attribute to a link generated with a Rails helper, you just need to specify it in the html_options hash argument to link_to (or whatever link helper you’re using).

For example:

<%= link_to 'Vote', { :action => 'vote' }, { :rel => 'nofollow' } %>

Voila! This should discourage web crawlers (such as the Google search crawler) from following links they shouldn’t and generating false ‘clicks’.

Categories: Technology


Jed · January 19, 2008 at 4:14 am

Sure did help. Oddly enough, I couldn’t find this basic info anywhere. Thanks!

Dave · January 8, 2012 at 5:41 pm

Thanks! Suggestion – don’t copy and paste this code. WordPress puts fancy quotes in place of the normal quotes, which will give you a syntax error!

Matt · January 8, 2012 at 5:52 pm

Thank you for pointing that out, Dave! I’ve updated the code snippet and copy and pasting should now work okay. (I’m using an explicit HTML code to prevent WordPress converting it.)

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *