If you have a bunch of text containing relative path hyperlinks, and you’d like to change to them to absolute paths, you might find this snippet helpful. content = “some text with a <a href=’/path/to/relative_link/’>relative link</a>” link = “http://somedomain.com/” content.gsub(/=(‘|”)//, ‘=1*/’).gsub(/*//, link.match(/(http|https)://[w.]+//)[0]) The asterisk ‘*’ is a hackey placeholder for the actual link swapped in …
Continue reading “Ruby on Rails Snippet for Changing Relative Paths to Absolute”