2010-10-30 75 views

回答

1

你可以在你的Rails项目中使用UUID宝石和一个varchar(字符串)列在表中:

http://rubygems.org/gems/uuid

然后在你的模型:

class MyModel < ActiveRecord::Base 
    before_save :generate_uuid 

    protected 
    def generate_uuid 
    self.uuid ||= UUID.new.generate # Fill an UUID in uuid field only if the field is nil 
    end 
end 
相关问题