2010-10-30 64 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 
相關問題