0 0 0 0


Rails 3.1 edge use sprockets to handle .js and .scss files. Sprockets use comments to deal with dependencies.

I put the three folders (dojo dijit dojox) in vendor/assets/javascripts. Then add a line in app/assets/javascripts/application.js //= require dojo/dojo console.log(dojo);

Now dojo has been merged into application.js. But dojo has dependency system itself. When I require more dojo modules. It cannot find the right path. dojo.require("dojox.grid.DataGrid"); // Error in webkit console: Error: Could not load 'dojox.grid.DataGrid'; last tried '../dojox/grid/DataGrid.js' // Error in rails server log: Started GET "/undefined../dojox/grid/DataGrid.js" for at Sat Apr 16 01:26:05 +0800 2011

These are two different dependency systems. How can I put them together?

Best Answer:

dojo.js doesn't take too naturally to being renamed. This is because part of Dojo's initialization process involves searching through the DOM for the script tag responsible for loading itself. It does this for two reasons:

  • Determine its baseUrl if not already specified
  • Pick up any djConfig (or data-dojo-config in 1.6+) properties specified in the script tag itself
  • When it searches for this script tag, it looks for one with src set to dojo.js or dojo.xd.js; it's not finding it in your case, thus the failures.

    It should be possible to work around both of these issues, by specifying djConfig (or dojoConfig in 1.6+) fully programmatically in another script tag before the one that loads Dojo, and by specifying baseUrl manually in these config properties.

    For example, if your application.js were in vendor/assets/javascripts as referred to in your original post, you could try doing this:

    <script type="text/javascript">
        //if you're using 1.5 or earlier, use djConfig instead of dojoConfig
        var dojoConfig = {
            //note that baseUrl points to the folder containing dojo.js, therefore the dojo folder
            baseUrl: 'vendor/assets/javascripts/dojo/'
    <script type="text/javascript" src="vendor/assets/javascripts/application.js"></script>

    For more information on dojo config settings: (in fact, that page actually has a note under baseUrl specifically about renamed dojo.js.)

    Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs