In rails 3 the application.js file was moved to assets>javascripts>application.js In this file there are pre-loaded comments that state:
Add new JavaScript/Coffee code in separate files in this directory and they’ll automatically
be included in the compiled file accessible from http://example.com/assets/application.js
It’s not advisable to add code directly here, but if you do, it’ll appear at the bottom of the
the compiled file.
However, in many tutorials like railscasts they add code into the application.js file all the time. This was back when application.js was still in the public folder. Should this code not be inside application.js in rails 3? Thanks in advance
I guess it depends on the application. If you have an application with just a few lines of javascript I would not put the JS in separate files. However for bigger applications it makes sense to have one file for each larger area of the app.
Additionally you still have the possibility to not include all the JS all the time, i.e. if you have a admin section, you could use the
javascript_include_tagto only includeadmin.jsin the relevant parts of your app.