Skip to content

Commit

Permalink
fixed DEPRECATION WARNING: Rails.application.secrets
Browse files Browse the repository at this point in the history
commit-id:9f758dec
  • Loading branch information
brand-it committed Apr 12, 2024
1 parent 8b94499 commit 0f84a4b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/tool_box/simply_encrypt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module SimplyEncrypt
MODE = 'AES-256-CBC'
KEY = Digest::SHA1.hexdigest(Rails.application.secrets.secret_key_base)[..31]
KEY = Digest::SHA1.hexdigest(Rails.application.credentials.secret_key_base)[..31]

def encrypt(data)
return [nil, nil] if data.blank?
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/secret_key_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# This will have a few costs like for
# example session becoming invalid on new devices and you can share cookies between multiple servers
# However you can still use the ENV["SECRET_KEY_BASE"] and all this does not mater
if Rails.application.secrets.secret_key_base.nil?
if Rails.application.credentials.secret_key_base.nil?
key_file = Rails.root.join("tmp/#{Rails.env}_secret.txt")
unless File.exist?(key_file)
random_key = SecureRandom.hex(64)
Expand All @@ -16,5 +16,5 @@
File.binwrite(key_file, random_key)
end

Rails.application.secrets.secret_key_base = ENV.fetch('SECRET_KEY_BASE', File.binread(key_file))
Rails.application.credentials.secret_key_base = ENV.fetch('SECRET_KEY_BASE', File.binread(key_file))
end

0 comments on commit 0f84a4b

Please sign in to comment.