Last Updated: February 25, 2016
·
1.672K
· ammoses89

Use twitter flight with rails

First remove the javascript_include_tag from application.html.erb. This will no longer be needed.

Then add a script tag for requirejs:

<script data-main="/assets/main.js" src="/assets/require/require.js"></script>

main.js is located in app/assets/javascripts. I use bower to manage js dependencies. So my main.js looks something like this:

require.config({
   baseUrl: '/assets',

   paths: {
      jquery: 'jquery/jquery',
      es5shim: 'es5-shim/es5-shim',
      es5sham: 'es5-shim/es5-sham'
   },

   shim: {
     '/assets/flight/lib/index': {
     deps: ['jquery', 'es5shim', 'es5sham']
   }  
 }

});

require(
    [
      '/assets/flight/lib/compose',
      '/assets/flight/lib/registry',
      '/assets/flight/lib/advice',
      '/assets/flight/lib/logger',
      '/assets/flight/tools/debug/debug'
     ],

     function(compose, registry, advice, withLogging, debug){
       debug.enable(true);
       compose.mixin(registry, [advice.withAdvice, withLogging]);
       require(['/assets/app'], function(initialize){
         initialize();
       });
      }
  );

1 Response
Add your response

Please, use lib/ and vendor/ for assets that are not strictly connected with your app.

over 1 year ago ·