Is there a ruby helper for creating absolute links from custom links if they are not absolute?
2 answers
Probably a good place to do this is before_save
on your model. I don't know of a predefined helper (although it auto_link
comes close), but a relatively simple regex should do the job:
class User < ActiveRecord::Base
before_save :check_links
def check_links
self.link = "http://" + self.link unless self.link.match /^(https?|ftp):\/\//
end
end
+3
a source to share