$([IPython.events]).on('notebook_loaded.Notebook', function(){
    // add here logic that should be run once per **notebook load**
    IPython.notebook.metadata.language = 'ruby' ;
});

$([IPython.events]).on('app_initialized.NotebookApp', function(){
    // add here logic that shoudl be run once per **page load**
    CodeMirror.requireMode('ruby', function(){
         console.log('Ruby mode should now be availlable in codemirror.');
    })
    IPython.CodeCell.options_default['cm_config']['mode'] = 'ruby';
    IPython.CodeCell.options_default['cm_config']['indentUnit'] = 2;
});

$([IPython.events]).on('notebook_loaded.Notebook', function(){
    // add here logic that should be run once per **notebook load**
    IPython.notebook.metadata.language = 'ruby' ;
});

$([IPython.events]).on('app_initialized.NotebookApp', function(){
    // add here logic that shoudl be run once per **page load**
    $.getScript('/static/components/codemirror/mode/ruby/ruby.js');
    IPython.CodeCell.options_default['cm_config']['mode'] = 'ruby';
    IPython.CodeCell.options_default['cm_config']['indentUnit'] = 2;
});

--- 
+++ 
@@ -5,7 +5,9 @@
 
 $([IPython.events]).on('app_initialized.NotebookApp', function(){
     // add here logic that shoudl be run once per **page load**
-    $.getScript('/static/components/codemirror/mode/ruby/ruby.js');
+    CodeMirror.requireMode('ruby', function(){
+         console.log('Ruby mode should now be availlable in codemirror.');
+    })
     IPython.CodeCell.options_default['cm_config']['mode'] = 'ruby';
     IPython.CodeCell.options_default['cm_config']['indentUnit'] = 2;
 });
Use CodeMirror RequireMode instead of getScript.

1) this will not get the mode if already on the page
2) this will work when IPython is run with a prefix.
