I am overriding the external_url= setter to ensure URLs start with http://. I’m doing this before any validation because I don’t want to bother the user who enters example.com/foo/bar without http://. I don’t plan on validating the URL at all anyway.
def external_url=(url)
if !url.match /^https?:\/\//i
url = "http://#{url}"
end
self[:external_url] = url
end
Looks legit! You use attr_accessor when you don't need to change the default behavior of the getter/setter. Don't forget to protect against mass assigment (http://railscasts.com/episodes/26-hackers-love-mass-assignment-revised) :)