I have these a coffeescript file for a model entree that just instanciates a class in another coffeescript file:
jQuery(document).ready ->
ch = new CepageHandling
ch.handleKeyPress()
The handlePress function captures keyup events on a control.
I have another model vin where I want to enable the same feature. I’m surprised to see I don’t need to do anything (it already has the same html), it’s already working, even though the coffeescript for the vin model is completely empty. I assume that the created javascript for entree gets called even when I’m not on this page.
I have seen the same behavior with scss files, where style defined for one model gets applied to others if the descriptors match. Can someone explain (or point to some article) if this is normal behavior that assets are not isolated in rails? I really have a hard time grasping how it works.
The default manifest files (
application.js, etc) dorequire_tree .which will load all files on all pages, concat them all together in production, etc. If you want things to be isolated you’ll need to put a test in yourreadyhandler to skip this code in some cases, or you’ll need more manifests (and not useapplication.jsfor example) to silo your code per page. I suggest you read every word of the asset pipeline Rails Guide very carefully… required reading!