Ruby on Rails 4 javascript not executed
$(document).ready(function() { } # Not working with turbo-links
From
Turbolinks overrides the normal page loading process, the event that
this relies on will not be fired. If you have code that looks like
this, you must change your code to do this instead:
$(document).on('ready page:load', function () {
// you code here
});
Another question
JavaScript not working in Ruby on Rails app
You can not access directly application.js or other js file functions from dom. Because rails use webpack for your codes. You can use events like this;
let openButton = document.querySelectorAll('button.openbtn')
openButton.addEventListener("click", function(event) {
document.getElementById("x").style.width = "15%";
})
let closeButton = document.querySelectorAll('button.closebtn')
closeButton.addEventListener("click", function(event) {
document.getElementById("mySidepanel").style.width = "0";
})
Rails 4 CoffeeScript not executing when precompiled
Finally found the problem, many thanks to @itsnikolay. The problem was due to the fact that another javascript file was throwing an exception. By having them all compiled into one single file, the exception would make the whole script stop running, thus not executing the Coffescripts.
In this particular case, it was due to the gem rails-assets-tether that was missing to provide tooltips from the bootstrap library.
When in debug mode, since, all javascript files are loaded independently, exceptions from one file doesn't affect loading the other ones.
Rails 4 - javascript files not loading in production but working well locally. (Heroku)
SOLVED:
In application.js I moved the file with the error to the bottom.
Everything seems to work fine.
Apparently in production mode files with warnings/error act differently.
Related Topics
Angular 2: Two Backend Service Calls on Success of First Service
How to Detect Scroll Position of Page Using Jquery
How to Validate a Radio Button
In R, How to Display Value on the Links/Paths of Sankey Graph
Wkwebview - Complex Communication Between JavaScript & Native Code
R Shiny Build Links Between Tabs
Set a Request Header in JavaScript
Javascript:For Loop with Timeout
How to Write Asynchronous Functions for Node.Js
How to Detect Faces Using Ruby
Simple Function to Sort an Array of Objects
Reactjs - Lifting State Up VS Keeping a Local State
How to Use Source: Function()... and Ajax in Jquery UI Autocomplete
Meteor: Calling an Asynchronous Function Inside a Meteor.Method and Returning the Result