I am not sure how rails_ujs.js works, but I think your problems are related to the fact that the html content that you add on the client side does not respond to events that have already been bound. The solution is that whenever you add a new HTML element on the client side, you also need to bind an event to it.
Consider the following example:
<html> <head> <title>My Page</title> <script src="jquery.js"></script> </head> <body> <div id="content"> <a href="#" class="link">Click me</a> </div> <a href="#" class="add_link">Add link</a> <script type="text/javascript"> $(document).ready(function(){ $('.link').click(function(){ alert('Click me'); }); $('.add_link').click(function(){ $("#content").append("<a href='#' class='link'>Click me no alert...</a>"); }); }); </script> </body> </html>
When you click on the βAdd Linkβ link, it will add a link saying that I click βIβ and I have a βlinkβ link. However, if you click this link, it will not display a warning, that is, the event event of the event does not fire, it only fires for content created on the server side.
The solution is described in more detail in this question: In jQuery, how to attach events to dynamic html elements?
However, I'm not sure how to apply it to rails_ujs, you will probably have to make some changes there.
source share