ruby on rails - add javascript
12,719
Solution 1
Adding your custom javascript to your rails app is real easy, just follow the steps below :-
- create a file (say custom.js) under app/assets/javascripts/
- Open up your manifest file i.e application.js (this is the file where you need to include every javascript file you want to load into your rails app, add the script name to it //=require custom.
- Visit your rails app from browser and check the page source and search for custom.js being loaded or not thats all.
Solution 2
For Rails 6
Add your javascript code under /app/javascript//file.js
and then in app/packs/application.js
require("<folder name>/file")
Author by
user2771150
Updated on July 24, 2022Comments
-
user2771150 almost 2 years
I'm a newbie ruby on rails developer. I've just created my first application and made use of the the
bootstrap
carousel. Now, I want to add somejavascript
. My application does not have any customjavascript
at this point. What I want to do is when theleft
orright
button on the carousel is pressed, I want analert
to pop up. Preferably, I want to include myjavascript
file in the/assets/javascript
directory. The purpose of this is to just learn how to add newjavascript
files in my application.