I am running Rails 4.0.1 and Ruby 2.0.0. I currently have a graph.js that takes inputs in from the user for a savings calculator in order to create a graph with d3 and the rickshaw.js graph.
My graph.js
file is saved in the app/assets/javascripts/graph.js
. I make a call to the Rickshaw graph with
var graph = new Rickshaw.Graph()
I am getting an error of Uncaught ReferenceError: Rickshaw is not defined.
The rickshaw.js
file is saved in vendor/javascript/rickshaw.js
along with d3.layout.js
and d3.vs.js
. If I save all of these files in the app/assets/javascripts
everything works fine, but that does not seem to be the correct rails way.
Does anyone know how to fix this error?
Thank you.
In previous versions of Rails, all assets were located in subdirectories of public such as images, javascripts and stylesheets. With the asset pipeline, the preferred location for these assets is now the app/assets directory. Files in this directory are served by the Sprockets middleware. Assets can still be placed in the public hierarchy.
Check ExecJS documentation to know all supported JavaScript runtimes. Pipeline assets can be placed inside an application in one of three locations: app/assets, lib/assets or vendor/assets. app/assets is for assets that are owned by the application, such as custom images, JavaScript files, or stylesheets.
By default Rails assumes assets have been precompiled and will be served as static assets by your web server. During the precompilation phase an SHA256 is generated from the contents of the compiled files, and inserted into the filenames as they are written to disk.
Rails comes bundled with a command to compile the asset manifests and other files in the pipeline. Compiled assets are written to the location specified in config.assets.prefix . By default, this is the /assets directory. You can call this command on the server during deployment to create compiled versions of your assets directly on the server.
To use the asset pipeline, you'll want just the filename in the require
statements:
// Vendor Files
//= require d3.v3
//= require d3.layout
//= require rickshaw
See the asset pipeline docs for more info on asset organization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With