Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4.0. vendor/assets/javascripts - Asset Pipeline issue

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.

like image 628
surgentt Avatar asked Nov 25 '13 16:11

surgentt


People also ask

Where are the assets in the rails asset pipeline?

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.

Where do I put pipeline assets in execjs?

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.

How are rails assets served to the server?

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.

How do I compile the assets in the pipeline?

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.


1 Answers

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.

like image 158
CDub Avatar answered Oct 06 '22 22:10

CDub