4

I've downloaded a javascript file called jquery.jsPlumb-1.2.6 and placed in my public/javascripts directory.

I want access to this file in one particular html.erb and several js.erbs. What is the best way to do that?

1

1 Answer 1

5

You can either use <%= javascript_include_tag :defaults %> in the HEAD section of your page (recommended): This function will return references to the JavaScript files created by the rails command in your public/javascripts directory. Using it is recommended as the browser can then cache the libraries instead of fetching all the functions anew on every request.

Or you can use<%= javascript_include_tag 'prototype' %>: As above, but will only include the Prototype core library, which means you are able to use all basic AJAX functionality. For the Scriptaculous-based JavaScript helpers, like visual effects, autocompletion, drag and drop and so on, you should use the method described above.

More info here mate.

http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html

Sign up to request clarification or add additional context in comments.

3 Comments

But I have downloaded a file that is not prototype or jquery... How do I include a file named sdfsdfdsf.js is my question. Not how to include prototype.
i think it would be <%= javascript_include_tag 'example.js' %>
For anyone reading this in 2017, :defaults does not appear to be a special argument to javascript_include_tag (or, at least not in Rails 5) — ActionView simply tries to load defaults.js from the asset pipeline.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.