Major changes in this commit over include work over several days but that was never...
[selectricity-live] / app / models / token.rb
diff --git a/app/models/token.rb b/app/models/token.rb
new file mode 100644 (file)
index 0000000..2bab513
--- /dev/null
@@ -0,0 +1,18 @@
+class Token < ActiveRecord::Base
+  belongs_to :vote 
+
+  def initialize
+    super
+
+    token_generator = UniqueTokenGenerator.new( 16 )
+    until not token.empty? and Token.find_all( [ "token = ?", token ]).empty?
+      self.token = token_generator.token
+    end
+
+    self
+  end
+
+  def to_s
+    self.token
+  end
+end

Benjamin Mako Hill || Want to submit a patch?