views:

69

answers:

2

If I want to generate a random string for a token in rails, can I use validates_uniqueness_of on it? Given that this isn't something a user will input or get an error back for it needs to be unique straight away. Or am I just being stupid?

A: 

validates_uniqueness_of will just make sure that the attribute is unique - it won't generate the value.

I'd use before_validation to create the unique value.

Mr. Matt
+1  A: 
Maximiliano Guzman
Might give that a go. Thanks
Cameron