snipt

Ctrl+h for KB shortcuts

Ruby

rails > get database configuration in console

Rails.configuration.database_configuration[Rails.env]
https://snipt.net/embed/90c39f5db690e5e18279fba23522d68b/
https://snipt.net/raw/90c39f5db690e5e18279fba23522d68b/
90c39f5db690e5e18279fba23522d68b
rb
Ruby
1
2016-02-09T04:24:43
True
False
/api/public/snipt/138105/
rails-get-database-configuration-in-console-8e5451d2
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</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></pre></div> </td></tr></table>
console, database, rails, ruby

Ruby

rails > override as_json in model

1
2
3
4
def as_json(options = {})
  super(options.merge(include: :authors,
           except: [:password_digest]))
end
https://snipt.net/embed/b8877bff1091216699f8c1dbb0a6cf46/
https://snipt.net/raw/b8877bff1091216699f8c1dbb0a6cf46/
b8877bff1091216699f8c1dbb0a6cf46
rb
Ruby
6
2016-02-11T10:59:37
True
False
Jun 30, 2013 at 02:54 PM
/api/public/snipt/66098/
rails-override-as_json-in-model
<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="k">def</span> <span class="nf">as_json</span><span class="p">(</span><span class="n">options</span> <span class="o">=</span> <span class="p">{})</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">super</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="kp">include</span><span class="p">:</span> <span class="ss">:authors</span><span class="p">,</span> </span><span id="L-3"><a name="L-3"></a> <span class="ss">except</span><span class="p">:</span> <span class="o">[</span><span class="ss">:password_digest</span><span class="o">]</span><span class="p">))</span> </span><span id="L-4"><a name="L-4"></a><span class="k">end</span> </span></pre></div> </td></tr></table>
rails, ruby
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.