0

I have a Ruby on Rails Application, with application.html.erb with the following body structure.

<Header>
  <anchor tags></anchor tags>
</Header>
<%= yield %>

On clicking the anchor tags in the header -> the content of the yield changes. But the window.onload only loads one time i.e. when the page loads for the first time, despite navigating through the anchor tags in the header. Due to which all the bindings and events which were handled inside the window.onload are getting lost.

How to add the same bindings and events when window.load is not getting called OR any alternative to window.onload using vanilla javascript that can solve the problem?

red-devil
  • 1,064
  • 1
  • 20
  • 34
  • 1
    You can move the js in the page which loads again which I guess is loaded from AJAX request or use event delegation. – Sahil Apr 23 '16 at 10:38

1 Answers1

1

A possible reason for this behavior is turbolink gem. Try to remove it if You haven't done it already.

kunashir
  • 917
  • 8
  • 21
  • But somehow the page loading speed reduces after this. Any way to keep Turbolinks and still make this work? – red-devil Apr 23 '16 at 12:02
  • Yes, for example look this http://stackoverflow.com/questions/18770517/rails-4-how-to-use-document-ready-with-turbo-links – kunashir Apr 23 '16 at 13:05