Operating environment Ruby 2.6.5 Rails 6.0.3.2
Basically, JavaScript occurs on all pages, so even on pages that do not use JavaScript, JavaScript errors will occur in the console of the verification tool. I finally solved it, so I posted it.
hoge.js
if (location.pathname.match("hoge")){
//Start writing JavaScript from here.
}
Now hoge.js will only work with the path hoge.
For the time being, if you put a commentary, you can get the current path by location.pathname and check if it matches hoge by match.
Personally, I was worried about JavaScript errors in the console, so this was neat.
Recommended Posts