You could notice that in Rails 7.1 shown warning message in logs:
W, [2024-10-21T15:34:51.142815 #472855] WARN -- : DEPRECATION WARNING: `Rails.application.secrets` is deprecated in favor of `Rails.application.credentials` and will be removed in Rails 7.2.
Yes, of course, you can transfer all the contents of the file config/secrets.yml
to config/credentials/production.yml.enc
by using
EDITOR=vim rails credentials:edit --environment production
But as for me, for an existing project, I want to stay on a simpler storage technology for configuration. In order to continue using the storage of configuration in the file config/secrets.yml
.
You only have to add one line to the configuration in your rails app:
# your config/application.rb file
module MyApp
class Application < Rails::Application
# ...
config.secrets = config_for(:secrets)
# ...
end
end
Next, replace all your appeals to Rails.application.secrets
with Rails.configuration.secrets
, e.g.:
class MyController < ApplicationController
def index
# my_var = Rails.application.secrets.dig(:my_config, :my_var)
my_var = Rails.configuration.secrets.dig(:my_config, :my_var)
# ...
end
# ...
end
Some useful links:
Rails::Application#config_for
- Custom Configuration
- Rails 7.1 removes the secrets:setup command and deprecates secrets:edit and secrets:show commands
- Remove deprecated
secrets:setup
anddeprecate secrets:edit/show
#47801 - Deprecate calling
Rails.application.secrets
#48472
If you have comments and suggestions, I will gladly read them in the comments.
Thank you for reading, good day to you!
Top comments (0)