In Ruby on Rails you can use regex to find urls and add rel=nofollow to them.
def add_nofollow html
html.scan(/(\<a href=["'].*?["']\>.*?\<\/a\>)/).flatten.each do |link|
if link.match(/\<a href=["'](http:\/\/|www){0,1}((localhost:3000|mysite.com)(\/.*?){0,1}|\/.*?)["']\>(.*?)\<\/a\>/)
else
link.match(/(\<a href=["'](.*?)["']\>(.*?)\<\/a\>)/)
html.gsub!(link, "<a href='#{$2}' rel='nofollow' target='_new' >#{$3}</a>" )
end
end
html
end
`
Cheers!