I started to use Turbolinks gem in my Rails 3 application project.
I use //= require_tree .
in my application.js
When using Turbolinks, I've just realized that some javascript codes stop working. According to the Railscasts page, the solution is by adding the following codes to the js file:
ready = ->
#some stuff
$(document).ready(ready)
$(document).on('page:load', ready)
And it starts working. So, I add the above codes to each of my controller js assets in order to make them work. I have a lot of javascript assets that correspond to my controller, such as:
- users.js.coffee
- posts.js.coffee
- settings.js.coffee
etc.
My question is:
Is it okay to repeat the above codes in every controller javascript assets file? Or should I just delete all the js controller assets, put them into one file, for example, let's say 'global.js.coffee
' and put all the logics inside the ready
function, so, I just need to write $(document).ready(ready)
and
$(document).on('page:load', ready)
once?