James Badger

Web Developer

Generate a New Secret Token for Rails Apps

Recently I had to build one Rails app off a clone of another Rails app. I wanted to find a quick way to change the secret token in config/initializers/secret_token.rb. IRB makes it easy:

$ irb
>> require 'securerandom'
=> true
>> SecureRandom.hex(64)
=> "3fe397575565365108556c3e5549f139e8078a8ec8fd2675a83de96289b30550a266ac04488d7086322efbe573738e7b3ae005b2e3d9afd718aa337fa5e329cf"
>> exit

Edit: Rails has actually built-in a Rake task (since 2007) to do this as well:

$ rake secret
82d58d3dfb91238b495a311eb8539edf5064784f1d58994679db8363ec241c745bef0b446bfe44d66cbf91a2f4e497d8f6b1ef1656e3f405b0d263a9617ac75e

Comments