Skip to content

Instantly share code, notes, and snippets.

@scottb
Created September 7, 2011 15:48
Show Gist options
  • Save scottb/1200943 to your computer and use it in GitHub Desktop.
Save scottb/1200943 to your computer and use it in GitHub Desktop.
Getting Dojo to work with Rails 3.1 and Sprockets
//= require_directory .
dojo.require('dojox.rails');
<!DOCTYPE html>
<html>
<head>
<title>Hellodojo</title>
<%= stylesheet_link_tag 'http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css' %>
<%= stylesheet_link_tag 'application' %>
<%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js', :'data-dojo-config' => %Q(dojoBlankHtmlUrl:'/blank.html', baseUrl: 'assets/', modulePaths: {custom: 'custom'}) %>
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>
</head>
<body class='claro'>
<%= yield %>
</body>
</html>
Dojo modules then go under app/assets/custom -- may be written in Coffeescript, if desired.
@scottb
Copy link
Author

scottb commented Oct 21, 2011

At the end of the first javacript_include_tag, it configures Dojo's modulePaths. In the example, it tells it to find modules starting with "custom" under the path "custom". So, if you create a module, say "custom.test", and put it app/assets/javascripts/custom/test.js, you'd load it with: dojo.require( "custom.test");

You can change the modulePaths in the include to be whatever you need for your particular modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment