snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#28360

Ruby

Get current environment database configuration.

1
2
3
4
Rails.configuration.database_configuration[Rails.env]


=> {"encoding"=>"unicode", "username"=>"postgres", "adapter"=>"postgresql", "port"=>5432, "host"=>"localhost", "password"=>"postgres", "database"=>"mydb", "pool"=>5}
https://snipt.net/embed/1cc7c0a5f6940605863a6e551117f669/
https://snipt.net/raw/1cc7c0a5f6940605863a6e551117f669/
1cc7c0a5f6940605863a6e551117f669
rb
Ruby
4
2014-04-15T22:32:59
True
False
/api/public/snipt/28360/
get-current-environment-database-configuration
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="no">Rails</span><span class="o">.</span><span class="n">configuration</span><span class="o">.</span><span class="n">database_configuration</span><span class="o">[</span><span class="no">Rails</span><span class="o">.</span><span class="n">env</span><span class="o">]</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="o">=&gt;</span> <span class="p">{</span><span class="s2">&quot;encoding&quot;</span><span class="o">=&gt;</span><span class="s2">&quot;unicode&quot;</span><span class="p">,</span> <span class="s2">&quot;username&quot;</span><span class="o">=&gt;</span><span class="s2">&quot;postgres&quot;</span><span class="p">,</span> <span class="s2">&quot;adapter&quot;</span><span class="o">=&gt;</span><span class="s2">&quot;postgresql&quot;</span><span class="p">,</span> <span class="s2">&quot;port&quot;</span><span class="o">=&gt;</span><span class="mi">5432</span><span class="p">,</span> <span class="s2">&quot;host&quot;</span><span class="o">=&gt;</span><span class="s2">&quot;localhost&quot;</span><span class="p">,</span> <span class="s2">&quot;password&quot;</span><span class="o">=&gt;</span><span class="s2">&quot;postgres&quot;</span><span class="p">,</span> <span class="s2">&quot;database&quot;</span><span class="o">=&gt;</span><span class="s2">&quot;mydb&quot;</span><span class="p">,</span> <span class="s2">&quot;pool&quot;</span><span class="o">=&gt;</span><span class="mi">5</span><span class="p">}</span> </span></pre></div> </td></tr></table>
config, db, ruby