Hi there, I have a web app that allows users to edit model data via a popup window. When the popup window form is completed, the user clicks a "Save" button, the window closes, and the original page reloads to show any updates that happened to the data.
My technique only works sometimes. I can't for the life of me figure out why it works one time and why it doesn't another.
In my popup window's form, I have this as the submit method:
<%= submit_tag("Update Invoice", {:onclick=>"refreshParent()"}) %>
So the Javascript is executed ideally at the same time that the form is submitted to the controller. Here's the refreshParent() Javascript function:
function refreshParent(id) {
window.opener.location.reload();
window.close();
}
Now, the method called by my form ("update" in this case) doesn't have a redirect_to method call, but even when I do (say, to the original view, index) it doesn't seem to matter.
At root, it seems that my controller method doesn't fire on form submit. Sometimes. I can submit the same form data multiple times, and it'll work the third time. Or sometimes it works right away. It's totally random.
What can I do to ensure that my controller methods fire when you close a popup window?
Thanks, Aaron.