# NewbieQ: How do I refresh view after return from popup windo

**URL:** <https://www.ruby-forum.com/t/newbieq-how-do-i-refresh-view-after-return-from-popup-windo/51715>\
**Category:** Rails\
**Created:** [January 6, 2006, 7:37am UTC](https://www.ruby-forum.com/t/newbieq-how-do-i-refresh-view-after-return-from-popup-windo/51715 "2006-01-06T07:37:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [January 6, 2006, 7:37am UTC](https://www.ruby-forum.com/t/newbieq-how-do-i-refresh-view-after-return-from-popup-windo/51715/1 "2006-01-06T07:37:31Z")

</div>

Hi,  
I have this bitta code that is supposed to open a new window and allow  
the user to create a new Organisation on the fly whilst editing a new  
Person i.e. if the Organisation exists they can select it from the drop  
down select. Otherwise they can click on the cute button and enter a  
skeleton Organisation record. What I need to do next is refresh the drop  
down select on returno the new organisation is shown and selected.

I have no idea how to do that - Any ideas? BTW - I’m not yet using AJAX

Usual Person data… Name, Position, etc  
Then;

\<%= link\_to(image\_tag("new\_organisation.png", :alt =\> 'New', :border =\>1), { :controller =\> 'organisations', :action =\> 'new'}, :popup =\> ['new\_window', 'height=100,width=100']) %\> \<%= options\_from\_collection\_for\_select @org, "id", "organisation\_name", @person.organisation\_id %\>

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [October 2, 2006, 9:38pm UTC](https://www.ruby-forum.com/t/newbieq-how-do-i-refresh-view-after-return-from-popup-windo/51715/2 "2006-10-02T21:38:58Z")

</div>

I would be very interested in this question too…has anybody  
figured this out?

Thanks  
Victor

Eric S. wrote:

> Hi,  
> I have this bitta code that is supposed to open a new window and allow  
> the user to create a new Organisation on the fly whilst editing a new  
> Person i.e. if the Organisation exists they can select it from the drop  
> down select. Otherwise they can click on the cute button and enter a  
> skeleton Organisation record. What I need to do next is refresh the drop  
> down select on returno the new organisation is shown and selected.
> 
> I have no idea how to do that - Any ideas? BTW - I’m not yet using AJAX
> 
> Usual Person data… Name, Position, etc  
> Then;
> 
> \<%= link\_to(image\_tag("new\_organisation.png", :alt =\> 'New', :border =\>1), { :controller =\> 'organisations', :action =\> 'new'}, :popup =\> ['new\_window', 'height=100,width=100']) %\> \<%= options\_from\_collection\_for\_select @org, "id", "organisation\_name", @person.organisation\_id %\>

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [October 2, 2006, 11:51pm UTC](https://www.ruby-forum.com/t/newbieq-how-do-i-refresh-view-after-return-from-popup-windo/51715/3 "2006-10-02T23:51:02Z")

</div>

I’d be too… will try tomorrow… with some Ajax request…

Victor wrote:

> I would be very interested in this question too…has anybody  
> figured this out?
> 
> Thanks  
> Victor

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [October 3, 2006, 12:04am UTC](https://www.ruby-forum.com/t/newbieq-how-do-i-refresh-view-after-return-from-popup-windo/51715/4 "2006-10-03T00:04:15Z")

</div>

> Eric S. wrote:

> > What I need to do next is refresh the drop  
> > down select on returno the new organisation  
> > is shown and selected.
> > 
> > I have no idea how to do that - Any ideas?  
> > BTW - I’m not yet using AJAX

You need to be using Ajax (probably via RJS). Put the drop-down in a

and re-render it after you're done entering the new Org record.

To learn RJS, I strongly recommend Cody F.'s “RJS Templates” PDF  
from  
O’Reilly. One of the best $10 I ever spent to learn a new programming  
tool  
/ technique.

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [October 3, 2006, 11:44am UTC](https://www.ruby-forum.com/t/newbieq-how-do-i-refresh-view-after-return-from-popup-windo/51715/5 "2006-10-03T11:44:55Z")

</div>

AJAX seems like a good option here. But if you don’t want to get into  
that and don’t mind the whole page being refreshed you could also try  
something like this:

- Add a hidden field to your form called “organisation\_added” which is  
set to false by default.
- Then when an organisation is added, use JavaScript to set  
“organisation\_added” to true and post the form.
- Then with Ruby, if params[‘organisation\_added’] is set to true create  
a person object using the data that has already been entered (@person =  
Person.new(params[:person]) ), and re-render the form.
- params[‘organisation\_added’] == false means the user posted the form  
manually, so in that case you can save the person to your DB.

Good luck!

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [October 3, 2006, 4:59pm UTC](https://www.ruby-forum.com/t/newbieq-how-do-i-refresh-view-after-return-from-popup-windo/51715/6 "2006-10-03T16:59:55Z")

</div>

In Javascript window.opener is your reference to the parent window,  
i.e. the window it was popped up from. Example:

In your main page where the form exists:

In the pop-up page:

---

<div class="post-metadata">

**Author:** ![soderic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8baadc/32.png) [@soderic](https://www.ruby-forum.com/u/soderic)\
**Post date:** [October 3, 2006, 3:09pm UTC](https://www.ruby-forum.com/t/newbieq-how-do-i-refresh-view-after-return-from-popup-windo/51715/7 "2006-10-03T15:09:39Z")

</div>

Hi

> - Then when an organisation is added, use JavaScript to set  
> “organisation\_added” to true and post the form.

How to do this bit?

In particular how to use javascript from the popup to reference the page  
it was popped up from. Also how to set the field and post the form  
whilst not loosing any of the data already entered?

In my case I want to let the user enter som Lat/Lon position data, OR  
for convenience popup a google maps object and have it fill in the  
details in the original form when the user clicks on a location. I  
don’t feel that I need to post the form, just figure out how to  
reference back from the popped up page back to the original page?

Cheers

Ed W
