I am working a MIS which have some customer management work. When the
customer object is creating, we need to generate a unique code for the
customer. When in oracle, I created a sequence to solve the problem.
But now I migrated to mysql, and I tried to use the id created by auto-
increment. But it fails because it have to call save in after_save,
causing a infinite loop. what I want is a unique 6 digit number to
append to the code,which I use self.id.to_s in my error code.
thx in advance for your reply
class Customer < ActiveRecord::Base
CTYPES = [
['Annual Corp', 'A']
nation = Nation.find(nation_id)
self.code = nation.nation_code + ctype + Time.now.year.to_s +