Archive for January, 2008

Calling a rake task from rails code.

« 23 January 2008 | 13:52 | rake, ruby, rubyonrails | No Comments »

1) Require rake and load the rake files containing the tasks and dependencies you want to run:
require ‘rake’
load File.dirname(__FILE__) + ‘/../vendor/rails/railties/lib/tasks/misc.rake’
load File.dirname(__FILE__) + ‘/../vendor/rails/railties/lib/tasks/databases.rake’
2) invoke the task
Rake::Task[”db:test:prepare”].invoke



delete and delete_all don’t trigger callbacks

« 10 January 2008 | 14:01 | rubyonrails | No Comments »

I’m sure this isn’t earth shattering to anyone but I had forgotten about it and it caused me some head scratching yesterday.



Base classes get stored by ActiveRecord with type = NULL when using STI…

« 10 January 2008 | 13:53 | active record, rubyonrails | No Comments »

So you make sure you take that into consideration when crafting find_by_sql queries on STI tables.
For example when looking for all but one type in the table:
AND ( g.type != ? OR g.type IS NULL )



sudo !!

« 4 January 2008 | 0:24 | linux | No Comments »

I just discovered this handy linux command to repeat the last command from history as sudo:
sudo !!
I’m sure this is probably old news to most people.