Reputation: 1071
I'd like my URLS to be a random mix of characters (like YouTube does at the end of video URLS)
Is there a gem to do this? Can I link my UUIDs to each post so that a random mix of numbers is created?
Any advice would be appreciated - been looking for some sort of solution for days (well at this rate, nights)!
Upvotes: 1
Views: 111
Reputation: 3041
You can use UUIDs if you wish. I use postgres as my database and it has a UUID datatype now that can be used as the primary key for a database table rather easily. I also use code to "compress" the UUID down to 22 characters (see How can I shorten a UUID to a specific length? for information) and then use that as the id. It takes little code to accomplish this.
It's also possible to just use plain random strings of characters using SecureRandom (http://ruby-doc.org/stdlib-2.1.2/libdoc/securerandom/rdoc/SecureRandom.html) if you want, there are various ways of doing it.
Upvotes: 2