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 1ca29c478d607031ca6c5864046057a2

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 1c6e4ff8a3cf25e255ba8161b77cf40ea572a90541c8d111b51203e35d95a5c08bc826660911c09b48554efdbb45e58de1ee37080b505764c79ff2df40bc4a82

If you would like to read about more cool things you can do with rails on the command line, check out the guide.

http://guides.rubyonrails.org/command_line.html