Module: HasHashcode
- Defined in:
- lib/has_hashcode.rb
Defined Under Namespace
Classes: Railtie
Instance Method Summary collapse
Instance Method Details
#has_hashcode ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/has_hashcode.rb', line 12 def has_hashcode class_eval do def generate_hashcode begin self.hashcode = ActiveSupport::SecureRandom.hex(3).upcase end while !valid? && errors.on(:hashcode).present? end end before_create :generate_hashcode validates_uniqueness_of :hashcode, :allow_nil => true end |