Every time I change a .coffee file in the development mode, Rails creates a corresponding .js file in the same /javascripts directory. With the result that Rails ends up processing both the files and therefore instead of firing an event once, I end getting that event firing twice. I have to remember to manually delete the .js file so I get the correct and anticipated behavior.
My question is: how can I prevent Rails from generating the .js file in the first place? Is it not supposed to compile the .coffee file in memory in the development mode? when I delete the generated .js file, I get the correct and anticipated behavior?
Thanks.
Bharat
Check the
<head>section of your page. You check it by viewing the source of the page when running your app. If you do so I would bet that you will see one or more .js files that are included twice. Make sure you don’t have unnecessary javascript_include_tags somewhere in your views.Unless you changed the default require statements in
app/assets/javascripts/application.js, any javascript files that are in there are being automatically included as long as your layout is set to include them (which it is by default).Specifically, if you have this line in your application.js:
or
That will cause all .js files in the app/assets/javascripts directory (and sub directories if you have require_tree) to be included where you have the following in your page:
Usually this will be the case as it will be in your default layout (in
app/views/layouts/application.html.erb).So if they are already included in your layout you want to make sure you’re not including them again any other way.
Another thing you could try is to remove the include from your layout and then just include javascript files manually per view using
javascript_include_tag.