Add the following to the head of your template file
Assuming the above file structure loading each of the following urls would include:
mydomain.com/users # includes users.js mydomain.com/users/edit/1 # includes users.js and edit.js mydomain.com/users/show/1 # includes users.js mydomain.com/roles # includes roles.js mydomain.com/accounts # no files included mydomain.com/accounts/show/1 # includes show.js and show-new-edit-create.js mydomain.com/accounts/new # includes show-new-edit-create.js mydomain.com/accounts/edit/1 # includes show-new-edit-create.js mydomain.com/accounts/create # includes show-new-edit-create.js
Thanks to geoffgarside http://github.com/geoffgarside for also creating a version that can include the same file in multiple views. Some of the code comments are from his version as they are more concise than mine.