Sha256: 4b8c858a8a3b834221fff63ddb660df83d47651a249d8c119bb0e0586d6b984b
Contents?: true
Size: 517 Bytes
Versions: 1
Compression:
Stored size: 517 Bytes
Contents
module HasHashcode class Railtie < Rails::Railtie railtie_name :has_hashcode initializer "railtie_name.hook_into_active_record" do ActiveRecord.base_hook do include HasHashcode end end end def self.has_hashcode before_create :generate_hashcode validates_uniqueness_of :hashcode, :allow_nil => true end def generate_hashcode begin self.hashcode = ActiveSupport::SecureRandom.hex(3).upcase end while !valid? && errors[:hashcode].present? end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
has_hashcode-0.1.1 | lib/has_hashcode.rb |