Last Updated: February 25, 2016
·
1.878K
· 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 ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside