Sha256: ca1bc47c52b213e7e54f7df52bc233f91132513a2869e16b097fd982671df42e
Contents?: true
Size: 697 Bytes
Versions: 1
Compression:
Stored size: 697 Bytes
Contents
module UrlField def self.included(base) base.extend UrlFieldMethod end module UrlFieldMethod def url_field(field) before_save :clean_url_field class_eval do define_method(:clean_url_field) do self.send("#{field}=", send("cleaned_#{field}")) end private define_method("cleaned_#{field}") do return nil if send(field).nil? or send(field).blank? return "http://#{send(field)}" unless send(field).match(/https?:\/\/.*$/) send(field) end end end end end if Object.const_defined?("ActiveRecord") ActiveRecord::Base.send(:include, UrlField) end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
url_field-0.0.1 | lib/url_field.rb |