P
A
B
C
A
S
Thoughts, links, pictures on music, food, wine, film, tech etc.
2009-06-06
I wrote this:
Rails plugin: Accepting "http://" or not on a URL field
Sometimes, you have a field on an ActiveRecord Rails model that stores a URL. The user might enter "http://" or they might not. I had this problem, solved it for one model, then needed it for another one. It's plugin baby time!
So I made the world's simplest URL field plugin
Just throw the "url_field" into your class:
class Company
url_field :website
end
@company = Company.new
@company.website = "www.example.com"
@company.save
@company.website #=> "http://www.example.com"
Available now, free on Github
Update: Des and James were quick to point out that my initial release would incorrectly add "http://" to "https://" URLs. Quick patch!