Generating a secret with rails
Rails comes with a lot of helpful tools out of the box, thats part of what makes it such a pleasure to work with. It frequently feels like they have thought of pretty much everything, like it has been developed by a team who really cares about web development and lives through many of the daily tasks involved in web development.
Lately I have needed to manually generate random API keys for users, and the easiest way that I found was
date | md5. It works, thats for sure. But something just feels a little too hacky about it.
$ date | md5
Thats when I discovered that rails comes with a rake task for generating keys intended to be used as the session secret for your project. Just run
rake secret in your project root.
$ be rake secret
If you would like to read about more cool things you can do with rails on the command line, check out the guide.