Created
February 5, 2013 02:37
-
-
Save murajun1978/4711679 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :secret do | |
secret_token_file = Rails.root.join('config', 'initializers', 'secret_token.rb') | |
file secret_token_file do | |
require 'securerandom' | |
token = SecureRandom.hex(64) | |
require 'active_support/core_ext/string/strip' | |
application_name = Rails.application.class.name | |
content = <<-EOS.strip_heredoc | |
#{application_name}.config.secret_token = '#{token}' | |
EOS | |
secret_token_file.open('w') do |f| | |
f.write(content) | |
end | |
puts "Generated secret token and write it to #{secret_token_file.relative_path_from(Rails.root)}" | |
end | |
desc 'Generate secret token' | |
task generate: secret_token_file | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment