On Wednesday, June 18, 2014 2:46:29 AM UTC-4, Ruby-Forum.com User wrote:
>
> Hello people, I'm wondering why this is not working. I have some plain 
> JavaScript wrote on mycontroller.js , works like a charm; I'm listening 
> to few events of the related view and works. I've been writing some 
> code, testing it manually refreshing the page in the browser and goes 
> ok. 
>  The problem arise when I come to this view from another view. I have a 
> side-bar, when I click an <a> element it calls another action and render 
> another view. When I click the link which takes me to an action of 
> `mycontroller` controller the JavaScript work doesn't work, doesn't get 
> executed. Why is this? 
>  I'm listening to the events by: 
>
>  window.onload = function() { 
>    document.getElementById('my_element').onclick = function() { 
>      // do stuff... 
>    } 
>
>    // another listen... 
> } 
>
>  I'm wondering if I should use another event more than window.onload , 
> perhaps that doesn't get triggered when I come to this specific view 
> from an <a> HTML element. Do you have any clue about what's happening? 
> Thanks for your time, I appreciate it. 
>
> -- 
> Posted via http://www.ruby-forum.com/. 
>

It's hard to say, you would need to follow it in a browser that has tools 
for that such as firebug in Firefox.  Chrome and Safari also have good 
developer tools.  My guess would be turbolinks.   If you are using Rails 4, 
turbolinks is installed by default.  Turbolinks regenerates the page's 
content without loading a new page.  Therefore, document.ready and 
window.onload aren't triggered.  You need to use one of turbolink's events, 
such as page:change.  See documentation at the following:

https://github.com/rails/turbolinks

If that's not it, I would need more information.  

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/6cc19be5-9f6c-4352-9614-314a50cda712%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to