Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

include a JS file outside the asset pipeline in rails 3.1?

I would like to include some js files that are not in the asset pipeline, i tried to include with rails.root and the full path to those files but that is not working cause of permissions.

I know i can manually include every single JS file in my asset pipeline JS application.js but that would be a lot of work since my JS change a lot during development, so it would be nice if there was a way to include a js file outside asset pipeline.

Anyone has some suggestions on how I could approach this?

like image 287
Rubytastic Avatar asked Dec 21 '22 05:12

Rubytastic


2 Answers

You can put the file in the old pre-3.1 location /public/javascripts and link to it manually.

like image 176
Richard Hulse Avatar answered Feb 22 '23 23:02

Richard Hulse


If you don't want your assets to be processed by Sprockets, put them into the public folder (not public/assets, that's where the compiled assets are) and then you can access them as static resources, i.e. don't reference them with the javascript_include_tag helper method, but the good old HTML way.

For example I have an OpenLayers.js file that doesn't work well with the assets pipeline, so I add it to the public/javascripts folder and then in the header of my layout I link to it like that:

<script src="/javascripts/OpenLayers.js"></script>
like image 45
Petr Smejkal Avatar answered Feb 23 '23 00:02

Petr Smejkal