Hey Guys, first post here. I am running into some basic problems. I am trying to submit a form in a popup window and if the object saves close the popup window and refresh the page in the main window. Has anyone done this, or know a good way to do this? Sorry for such a stupid question, but I have ran around in circles trying to do this. Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The best way to do it, in my mind, is to use an rjs template. In your controller, your action would look something like this: def my_action # do usefull stuff. ... render :update do | page | if @something.save page << "myCloseWindowJavaScript()" else page << "notifyUserOfError()" end end end where myCloseWindowJavaScript() and notifyUserOfError are javascript functions you define in a .js file. You can also look at the documentation for ActionView::Helpers::PrototypeHelper::JavaScriptGenerator::GeneratorMeth ods http://api.rubyonrails.org/files/vendor/rails/actionpack/lib/ action_view/helpers/prototype_helper_rb.html On Aug 20, 2007, at 2:09 PM, Nicholas E. Hubbard wrote:> > Hey Guys, first post here. > > > I am running into some basic problems. I am trying to submit a form in > a popup window and if the object saves close the popup window and > refresh the page in the main window. > > Has anyone done this, or know a good way to do this? > > Sorry for such a stupid question, but I have ran around in circles > trying to do this. > > Thanks > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> I am running into some basic problems. I am trying to submit a form in > a popup window and if the object saves close the popup window and > refresh the page in the main window.rjs / ajax could work (above post), but don''t forget to use <% form_remote_tag %> rather than <% start_form_tag %> so the ajax works. this could be a problem if you want to upload pictures in the popup window (ajax does not allow this as of now) , so a different option could be the following: first of all, make sure the window is a popup that was ''popped-up'' from the MainWindow (if it is a target="_blank" the js functions won''t work on it). then, render js text: <script> window.opener.location.reload(); window.close(); </script> or something similar. hope this helps, and welcome to the forum! :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> render :update do | page | > if @something.save > page << "myCloseWindowJavaScript()" > else > page << "notifyUserOfError()" > end > end > end...wanted to fix myself; note that doing render :update is actually rendering the javascript (and not necessarily using ajax), so you should end up having something like render :update do | page | if @something.save page << ''window.opener.location.reload();'' page << ''window.close();'' else page << ''some_other_js_func();'' end end end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---