<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Artem Yegorov</title>
    <description>The latest articles on DEV Community by Artem Yegorov (@yegorov).</description>
    <link>https://dev.to/yegorov</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F103733%2F7451b854-1831-46b3-9d69-1c136663adb6.jpeg</url>
      <title>DEV Community: Artem Yegorov</title>
      <link>https://dev.to/yegorov</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yegorov"/>
    <language>en</language>
    <item>
      <title>How to continue to use Rails.application.secrets in Rails &gt;= 7.2</title>
      <dc:creator>Artem Yegorov</dc:creator>
      <pubDate>Mon, 21 Oct 2024 13:10:00 +0000</pubDate>
      <link>https://dev.to/yegorov/how-to-continue-to-use-railsapplicationsecrets-in-rails-72-32c7</link>
      <guid>https://dev.to/yegorov/how-to-continue-to-use-railsapplicationsecrets-in-rails-72-32c7</guid>
      <description>&lt;p&gt;You could notice that in Rails 7.1 shown warning message in logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;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.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes, of course, you can transfer all the contents of the file &lt;code&gt;config/secrets.yml&lt;/code&gt; to &lt;code&gt;config/credentials/production.yml.enc&lt;/code&gt; by using&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;EDITOR=vim rails credentials:edit --environment production&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;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 &lt;code&gt;config/secrets.yml&lt;/code&gt;.&lt;br&gt;
You only have to add one line to the configuration in your rails app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# your config/application.rb file&lt;/span&gt;
&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;MyApp&lt;/span&gt;
  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Application&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Application&lt;/span&gt;
    &lt;span class="c1"&gt;# ...&lt;/span&gt;
    &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;secrets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;config_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:secrets&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# ...&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, replace all your appeals to &lt;code&gt;Rails.application.secrets&lt;/code&gt; with &lt;code&gt;Rails.configuration.secrets&lt;/code&gt;, e.g.:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ApplicationController&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;
    &lt;span class="c1"&gt;# my_var = Rails.application.secrets.dig(:my_config, :my_var)&lt;/span&gt;
    &lt;span class="n"&gt;my_var&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configuration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;secrets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:my_config&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:my_var&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# ...&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
  &lt;span class="c1"&gt;# ...&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some useful links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://api.rubyonrails.org/classes/Rails/Application.html#method-i-config_for" rel="noopener noreferrer"&gt;&lt;code&gt;Rails::Application#config_for&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://guides.rubyonrails.org/configuring.html#custom-configuration" rel="noopener noreferrer"&gt;Custom Configuration&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.shakacode.com/blog/rails-7-1-removes-secret-setup-command-and-deprecates-secret-show-edit-commands/" rel="noopener noreferrer"&gt;Rails 7.1 removes the secrets:setup command and deprecates secrets:edit and secrets:show commands&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/rails/rails/pull/47801" rel="noopener noreferrer"&gt;Remove deprecated &lt;code&gt;secrets:setup&lt;/code&gt; and &lt;code&gt;deprecate secrets:edit/show&lt;/code&gt; #47801&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/rails/rails/pull/48472" rel="noopener noreferrer"&gt;Deprecate calling &lt;code&gt;Rails.application.secrets&lt;/code&gt; #48472&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have comments and suggestions, I will gladly read them in the comments.&lt;br&gt;
Thank you for reading, good day to you!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>secrets</category>
      <category>config</category>
    </item>
  </channel>
</rss>
