I want to use a javascript_link_tag to access a javascript file in a folder. Here is the path:
app/assets/javscripts/ntc.js
Please help me. Thanks.
I want to use a javascript_link_tag to access a javascript file in a folder. Here is the path:
app/assets/javscripts/ntc.js
Please help me. Thanks.
Since the file exist inside assets/javascript you can add in application.html.erb as follows:
<%= javascript_include_tag "ntc" %>
# => <script src="/assets/ntc.js"></script>
if you want to specify from other folder path then u can use as below:
<%= javascript_include_tag "xmlhr", host: "localhost", protocol: "https" %>
# => <script src="https://localhost/assets/xmlhr.debug-1284139606.js"></script>
As @Max mentioned, you can use asset pipeline to include controller specific stylesheets and JavaScript files only in their respective controllers.
If you have a folder of script files and want to load all for a particular controller for example:
assets
|
|___ javascript
|
|___ ntc.js
|
|___ ntc
|__script1.js
|__script2.js
Then you can require these files inside ntc.js as follows:
//= require ntc/script1
//= require ntc/script2
And can use
<%= javascript_include_tag params[:controller] %>
for more information refer this documentation