Skip to content

Commit 416c16e

Browse files
committed
generate secret_token dynamically...
see rails tutorial for details
1 parent 045fbef commit 416c16e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

config/initializers/secret_token.rb

+17-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,20 @@
99

1010
# Make sure your secret_key_base is kept private
1111
# if you're sharing your code publicly.
12-
Solar::Application.config.secret_key_base = '05f631010699c16c9768e141afce8173bc48c89207ee20599e2fc5489c725111b4f14f70b078a23cb673940c59f914a78577f4818ccf5812b955ea18a9b906f1'
12+
13+
require 'securerandom'
14+
15+
def secure_token
16+
token_file = Rails.root.join('.secret')
17+
if File.exist?(token_file)
18+
# Use the existing token.
19+
File.read(token_file).chomp
20+
else
21+
# Generate a new token and store it in token_file.
22+
token = SecureRandom.hex(64)
23+
File.write(token_file, token)
24+
token
25+
end
26+
end
27+
28+
Solar::Application.config.secret_key_base = secure_token

0 commit comments

Comments
 (0)