This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |