I'm working on a web application using rails. I have individual html.erb files where I run script.js on each file. I want to follow DRY so I want to put script.js in my layout's file instead of each individual view file.
Here is script.js:
if(document.documentElement.clientWidth < 570) {
//do some stuff
}
This works fine when I put it in each of my view individually but doesn't work when I only put it in my layouts file. I have a feeling that this is because I am using document. If this is true I'm not sure what I should replace document with. If this is not true then I'm not sure what is wrong.
If you could help me understand why script.js doesn't work when I put it in the layouts file that would be greatly appreciated.