Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Text only

Get top date

ClassRoom.where(course_id: idcourse).maximum(:last_cooking_date)
https://snipt.net/embed/302c30fb427fb963b07f7c395a6615bd/
https://snipt.net/raw/302c30fb427fb963b07f7c395a6615bd/
302c30fb427fb963b07f7c395a6615bd
text
Text only
1
2016-12-03T13:57:17
True
False
False
Jan 19, 2016 at 10:44 AM
/api/public/snipt/143679/
get-top-date
<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></span><span id="L-1"><a name="L-1"></a>ClassRoom.where(course_id: idcourse).maximum(:last_cooking_date) </span></pre></div> </td></tr></table>
active_record, rails

Text only

scope rails

includes(:class_room).where('class_rooms.course_id=? AND class_rooms.teacher_id=? AND student_histories.date = ? ',idcourse, idteacher, ClassRoom.where(course_id: idcourse).maximum(:last_cooking_date)).references(:class_room).order('student_histories.date ASC')
https://snipt.net/embed/3a8d7478c0cdd74209697c65c30d689a/
https://snipt.net/raw/3a8d7478c0cdd74209697c65c30d689a/
3a8d7478c0cdd74209697c65c30d689a
text
Text only
1
2016-12-09T01:39:22
True
False
False
/api/public/snipt/143678/
scope-rails
<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></span><span id="L-1"><a name="L-1"></a>includes(:class_room).where(&#39;class_rooms.course_id=? AND class_rooms.teacher_id=? AND student_histories.date = ? &#39;,idcourse, idteacher, ClassRoom.where(course_id: idcourse).maximum(:last_cooking_date)).references(:class_room).order(&#39;student_histories.date ASC&#39;) </span></pre></div> </td></tr></table>
model, rails, scope

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-12-08T15:37:20
True
False
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></span><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 migration in console

ActiveRecord::Migration.drop_table(:users)
https://snipt.net/embed/7c622ac35646103e349ee5de11a5224c/
https://snipt.net/raw/7c622ac35646103e349ee5de11a5224c/
7c622ac35646103e349ee5de11a5224c
rb
Ruby
1
2016-12-09T02:19:04
True
False
False
/api/public/snipt/135183/
rails-migration-in-console-94b98189
<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></span><span id="L-1"><a name="L-1"></a><span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Migration</span><span class="o">.</span><span class="n">drop_table</span><span class="p">(</span><span class="ss">:users</span><span class="p">)</span> </span></pre></div> </td></tr></table>
database, migration, rails, ruby

Ruby

activerecord > current database and tables

> ActiveRecord::Base.connection.current_database
> ActiveRecord::Base.connection.tables
https://snipt.net/embed/262b148fa0ff82559a980bb10c659a4e/
https://snipt.net/raw/262b148fa0ff82559a980bb10c659a4e/
262b148fa0ff82559a980bb10c659a4e
rb
Ruby
2
2016-12-09T04:53:11
True
False
False
/api/public/snipt/117401/
activerecord-current-database
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="o">&gt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Base</span><span class="o">.</span><span class="n">connection</span><span class="o">.</span><span class="n">current_database</span> </span><span id="L-2"><a name="L-2"></a><span class="o">&gt;</span> <span class="no">ActiveRecord</span><span class="o">::</span><span class="no">Base</span><span class="o">.</span><span class="n">connection</span><span class="o">.</span><span class="n">tables</span> </span></pre></div> </td></tr></table>
console, database, rails, ruby
Copyrighted, illegal, or inappropriate content? Email [email protected].