Blog » Blog Entry

Ruby on Rails HTML link helper

April 20, 2008

Sometimes you might want to link up any html links from a string of text:

def make_links( str )
  regex = Regexp.new '(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)'
  str.gsub( regex, '<a href="\1">\1</a>' )
end
Tags: rubyonrails

« Only creationists don't understand why people laugh at creationists.. Earthquake at 4:37am »

Add a comment:

Title:

Comment:

Name:

Email: