Skip to content

Instantly share code, notes, and snippets.

# config/initializers/nullify_blank.rb
class ActiveRecord::Base
def self.nullify_blank(*args)
for arg in args
define_method :"#{arg.to_s}=" do |v|
v = nil if v.blank?
self[arg.to_sym] = v
end
end
def get_random_string(length=5)
source=("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a + ["_","-","."]
key=""
length.times{ key += source[rand(source.size)].to_s }
return key
end
def get_random_string(length=5)
source=("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a + ["_","-","."]
key=""
length.times{ key += source[rand(source.size)].to_s }
return key
end