Notifications

Organising per view javascripts

I am refactoring my app since it is the first one and I have been doing the wrong things :)

This topic is about javascript assets. I have moved all the vendor libraries to the vendor folder and swapped min files with normal since rails does compress all.

I was also including page specific .js files in view depending on the libraries I needed and I have moved the bulk back to application.js as I noticed this was not the best practice.

Now I am dealing with view specific javascript. I am using this approach from Brandon Hilkert: controller and action name in body tag and return unless the relevant controller/action are shown.

Almost every controller index uses bootstrap table to list model items. These tables are initialised with javascript and some of the code such as action buttons and columns differ. Also the new/edit action for the same controller has specific javascript handling different features.

Following the above approach I could either create a separate file for each controller action (i.e. one for index and one for edit for each controller).