Topic: how do you organize javascript code in your rails project?
how do you organize javascript code in your rails project?
Here is how I organize javascript code in my current project: I include common javascript files on the bottom of a layout file and yield :javascript content. It looks like this:
= include_javascripts :common
....
= yield :javascript
Then in every page rendered, I put the related javascript code at the bottom of the page, it looks like this:
-content_for :javascript :javascript //code goes here…
The question is should I put the code in to a separate javascript file or it is okay to put javascript with the html content it manipulates? Any advantages and disadvantages?
In addition, there could be some javascript code that manipulate html content in partials, how do you organize them?
In summary, what is your best practice for organizing javascript code in your rails project(especially there are a lot of javascript code)?
Thanks.