Advertisement
Guest User

Untitled

a guest
Apr 17th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.26 KB | None | 0 0
  1. %w[save save!].each do |method_name|
  2.   define_method(method_name) do
  3.     self.slug = SecureRandom.hex(10) unless persisted?
  4.     super()
  5.   rescue ActiveRecord::RecordNotUnique => e
  6.     e.message.match?(/index_certificates_on_slug/) ? retry : raise
  7.   end
  8. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement